Python Beginner Notes
Python Beginner Notes
1. PRINTING OUTPUT
------------------
print("Hello, world!")
---------------------------
age = 25 # integer
-------------------
4. OPERATORS
------------
------------------
print("Hello", name)
6. IF-ELSE CONDITIONS
---------------------
print("Adult")
else:
print("Minor")
7. LOOPS
--------
While loop:
count = 0
print(count)
count += 1
For loop:
for i in range(5):
print(i)
8. LISTS
--------
print(fruits[0])
fruits.append("cherry")
len(fruits), fruits.remove("banana")
9. FUNCTIONS
------------
def greet(name):
print("Hello", name)
greet("Alice")
10. COMMENTS
------------
'''This is a
multi-line comment'''
s = "hello"
12. DICTIONARIES
----------------
print(person["name"])
person["age"] = 26
-----------------
------------------
try:
x = int("abc")
except ValueError:
print("Invalid input")
---------------------
import math
print(math.sqrt(16))
import random
print(random.randint(1, 10))