Learn Python Syntax: Beginner to Intermediate
1. Variables and Data Types
---------------------------
x=5 # Integer
y = 3.14 # Float
name = "Alice" # String
is_active = True # Boolean
2. Conditions and Loops
------------------------
if x > 3:
print("x is greater than 3")
elif x == 3:
print("x is 3")
else:
print("x is less than 3")
for i in range(5):
print(i)
while x > 0:
x -= 1
3. Functions
------------
def greet(name):
return f"Hello, {name}!"
print(greet("Alice"))
4. Lists, Tuples, Dictionaries
------------------------------
my_list = [1, 2, 3]
my_tuple = (1, 2, 3)
my_dict = {"name": "Alice", "age": 25}
my_list.append(4)
print(my_dict["name"])
5. File I/O
-----------
with open("[Link]", "w") as f:
[Link]("Hello, file!")
with open("[Link]", "r") as f:
print([Link]())
6. Common Libraries
-------------------
import math
print([Link](16))
import pandas as pd
df = [Link]({'a': [1, 2], 'b': [3, 4]})
7. Object-Oriented Programming (OOP)
------------------------------------
class Person:
def __init__(self, name, age):
[Link] = name
[Link] = age
def greet(self):
print(f"Hi, I'm {[Link]} and I'm {[Link]} years old.")
p = Person("Alice", 25)
[Link]()