Complete Python Guide
Complete Python Guide
1. Introduction to Python
Python is a high-level, interpreted programming language known for its simplicity and readability.
Example:
print("Hello, World!")
Example:
'''
This is a
multi-line comment
'''
Variables store data. Types: int, float, str, bool, list, tuple, dict, set
Example:
name = "Alice"
age = 25
5. Type Casting
Example:
int("5")
str(10)
Example:
print("Hello", name)
7. Operators
Arithmetic: + - * / % // **
age = 20
print("Adult")
print("Teen")
else:
print("Child")
i=0
Nested:
for i in range(3):
while True:
val = int(input())
if val > 0:
break
if i == 2: continue
if i == 4: break
print(i)
x=5
def func():
global x
x = 10
List: [1,2,3]
Tuple: (1,2)
Dict: {"a": 1}
Set: {1,2,3}
[x for x in range(5)]
{x for x in range(3)}
class Dog:
Dog("Tommy").bark()
try: 1/0
finally: print("Done")
print(math.sqrt(16))
dt = datetime.datetime.now()
json.dumps({'a':1})
import sys
print(sys.argv)
source env/bin/activate
import unittest
class T(unittest.TestCase):
Use snake_case, 4-space indents, proper naming. Use linters like flake8 or black.