Python CheatSheet ๐ โ
1. Basic Syntax
- Print Statement:
- Comments:
2. Data Types
- Integer:
- Float:
- String:
- List:
- Tuple:
- Dictionary:
3. Control Structures
- If Statement:
- For Loop:
- While Loop:
4. Functions
- Define Function:
- Lambda Function:
5. Exception Handling
- Try-Except Block:
6. File I/O
- Read File:
- Write File:
7. List Comprehensions
- Basic Example:
- Conditional Comprehension:
8. Modules and Packages
- Import Module:
- Import Specific Function:
9. Common Libraries
- NumPy:
- Pandas:
- Matplotlib:
10. Object-Oriented Programming
- Define Class:
11. Virtual Environments
- Create Environment:
- Activate Environment:
- Windows:
- macOS/Linux:
12. Common Commands
- Run Script:
- Install Package:
- List Installed Packages:
แแฎ Python checklist แ syntax, functions, แแฒแท coding skills แแฝแฑแแญแฏแธแแแบแ แฑแแแทแบ quick reference แกแแฑแแฒแท แกแแฑแฌแแบแกแแฐแแผแฏแแแบแแญแฏแแฐแแแซแแแบแแปแ
1. Basic Syntax
- Print Statement:
print("Hello, World!")- Comments:
# This is a comment2. Data Types
- Integer:
x = 10- Float:
y = 10.5- String:
name = "Alice"- List:
fruits = ["apple", "banana", "cherry"]- Tuple:
coordinates = (10, 20)- Dictionary:
person = {"name": "Alice", "age": 25}3. Control Structures
- If Statement:
if x > 10:
print("x is greater than 10")
- For Loop:
for fruit in fruits:
print(fruit)
- While Loop:
while x < 5:
x += 1
4. Functions
- Define Function:
def greet(name):
return f"Hello, {name}!"
- Lambda Function:
add = lambda a, b: a + b5. Exception Handling
- Try-Except Block:
try:
result = 10 / 0
except ZeroDivisionError:
print("Cannot divide by zero.")
6. File I/O
- Read File:
with open('file.txt', 'r') as file:
content = file.read()
- Write File:
with open('file.txt', 'w') as file:
file.write("Hello, World!")
7. List Comprehensions
- Basic Example:
squared = [x**2 for x in range(10)]- Conditional Comprehension:
even_squares = [x**2 for x in range(10) if x % 2 == 0]8. Modules and Packages
- Import Module:
import math- Import Specific Function:
from math import sqrt9. Common Libraries
- NumPy:
import numpy as np- Pandas:
import pandas as pd- Matplotlib:
import matplotlib.pyplot as plt10. Object-Oriented Programming
- Define Class:
class Dog:
def __init__(self, name):
self.name = name
def bark(self):
return "Woof!"
11. Virtual Environments
- Create Environment:
python -m venv myenv- Activate Environment:
- Windows:
myenv\Scripts\activate- macOS/Linux:
source myenv/bin/activate12. Common Commands
- Run Script:
python script.py- Install Package:
pip install package_name- List Installed Packages:
pip listแแฎ Python checklist แ syntax, functions, แแฒแท coding skills แแฝแฑแแญแฏแธแแแบแ แฑแแแทแบ quick reference แกแแฑแแฒแท แกแแฑแฌแแบแกแแฐแแผแฏแแแบแแญแฏแแฐแแแซแแแบแแปแ
โค4
programming basic - 7.pdf
3.8 MB
Programming basic concept - 7
๐กConcept แแฑแธแแญแฏ แแฌแธแแแบแแฝแฌแธแแแบ แแฑแทแแปแแทแบแแแบแธ แแฑแธแแฝแแบแธแแฑแธแแฒแท แกแแผแฑแแพแแบแแฑแธแแญแฏแแแบแธ แแฝแฑแธแแฑแธแแฒแทแแผแแซแกแฏแถแธแแป โก๏ธ
Anonymous Poll
30%
A
26%
B
37%
C
7%
D