Introduction to Python
Python is a user-friendly programming language that's great for
building websites, analyzing data, and creating smart applications.
It's easy to learn and helps you write code quickly!
Outline:
• Variables
• data types
• Comments
• user Input /Output
Variables and Data Types
A variable is a name that refers to a value stored in memory. You can think of it as a container that holds data.
You assign a value to a variable using the = operator.
data types:
1: Integers: Whole numbers, positive or negative.
num_apples = 10 # Example of an integer
2: Floats: Numbers with decimal points.
temperature = 23.5 # Example of a float
3:Strings: A sequence of characters enclosed in quotes.
greeting = "Hello, World!" # Example of a string.
4:Dictionaries: A collection of key-value pairs, created using curly braces. Keys are unique identifiers for the values.
student = {
"name": "Alice",
"age": 20,
"courses": ["Math", "Science"]
} # Example of a dictionary
Example
Variables
age = 25 # Integer
name = "Alice" # String
height = 5.6 # Float
Data Types
num_apples = 10 # Integer
temperature = 23.5 # Float
greeting = "Hello!" # String
fruits = ["apple", "banana", "cherry"] # List
student = { # Dictionary
"name": "Alice",
"age": 20,
"courses": ["Math", "Science" ]
}:
Comments in Python
Single-Line
Start with a # symbol. Everything after the # on that
line is considered a comment.
#This is a single-line comment
x = 10 # This assigns 10 to x
Multi-Line
Multi-line comments can be created using triple
quotes (''' or """)
""" This is a multi-line comment.
It can span multiple lines. """
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: ")
age = input("Enter your age: ")
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: ")
age = input("Enter your age: ")
Display output
print("Hello, " + name + "! You are " + age + " years old.")
THANK YOU