Introduction to Python
Introduction to Python
data types:
1: Integers: Whole numbers, positive or negative.
4:Dictionaries: A collection of key-value pairs, created using curly braces. Keys are unique identifiers for the values.
student = {
"name": "Alice",
"age": 20,
} # Example of a dictionary
Example
Variables
age = 25 # Integer
Data Types
num_apples = 10 # Integer
student = { # Dictionary
"name": "Alice",
"age": 20,
}:
Comments in Python
Single-Line
Start with a # symbol. Everything after the # on that
line is considered a comment.
x = 10 # This assigns 10 to x
Multi-Line
Multi-line comments can be created using triple
quotes (''' or """)
y = 20
User Input and Output
To get input from the user, you can use the input() function. By default, it treats the input as a string.
(Example)
name = input("Enter your name: ")
print("Hello, " + name + "! You are " + age + " years old.")
User Output
To display output, you can use the print() function. It can take multiple arguments and automatically adds spaces between them.
(Example)
print("Welcome to the program!")
Complete Example Here’s a complete example that
combines both input and output:
Get user input
name = input("Enter your name: ")
Display output
print("Hello, " + name + "! You are " + age + " years old.")
THANK YOU