
![]() |
@wtf | |
Variables & Data Types |
||
2
Replies
32
Views
3 Bookmarks
|
![]() |
@wtf | 8 August 25 |
Variables store data. Python automatically detects the type. Common Types & Examples: - int &8594; a = 10 - float &8594; pi = 3.14 - str &8594; name = Alice - bool &8594; is_online = True - list &8594; fruits = [apple, banana, mango] - tuple &8594; dimensions = (10, 20) - dict &8594; student = name: Rahul, age: 21 - set &8594; unique_nums = 1, 2, 3 Control Flow Use conditions & loops to control code flow. if-else Example: python temp = 35 if temp 30: print(It's hot) else: print(Pleasant weather) for loop Example: python for fruit in fruits: print(fruit) while loop Example: python i = 1 while i = 5: print(i) i += 1 Functions Reusable blocks of code using def. Function Example: python def greet(name): return fHello, name! Usage: python print(greet(Alia)) Output: Hello, Alia Functions keep your code neat, reusable, and easier to understand! |
||
![]() |
@koula | 13 days |
how to color text in phyton
|
||


