basic use of python programming
1. Variables and Data Types
Variables are containers used to keep data values.
name = "Alex"
age = 17
In Python, you dont need to define the data type manually.
2. Input and Output
These are used to receive input from users and display results.
name = input("Enter your name: ")
print("Hello,", name)
3. Conditional Statements
Used to control decisions in a program.
if age >= 18:
print("Adult")
else:
print("Minor")
4. Loops
Loops allow code to run repeatedly.
for i in range(5):
print(i)
5. Functions
Functions are blocks of code that can be reused.
def greet(name):
return "Hello " + name
6. Lists
Lists store multiple items in one variable.
numbers = [1, 2, 3]
7. Dictionaries
Used to store data with key-value pairs.
student = {"name": "Alex", "age": 17}
8. Error Handling
Prevents the program from crashing when errors occur.
try:
x = int(input())
except:
print("Error")
9. Comments
Comments help explain the code.
# this is a comment
10. Modules
Modules let you use built-in features or external libraries.
import math
Leave a Reply
You must be logged in to post a comment.