0% found this document useful (0 votes)
22 views19 pages

Python Basics: Print, Variables, Loops

Uploaded by

dineshcto24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views19 pages

Python Basics: Print, Variables, Loops

Uploaded by

dineshcto24
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Beginner Steps with Examples

Printing
The print() function is used to display output in Python.

Example:

print("Hello, World!") # Output: Hello, World!

Variables
Variables are used to store data values.

Example:

x=5
name = "Alice"
print(x)
print(name)

Conditionals
Conditional statements are used to perform different actions based on different conditions.

Example:

x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is 5 or less")

Loops
Loops are used to execute a block of code repeatedly.

Example:

for i in range(5):
print(i)

Functions
Functions are blocks of code that run when called and can accept parameters.
Example:

def greet(name):
print("Hello, " + name)
greet("Alice")

Lists
Lists are used to store multiple items in a single variable.

Example:

fruits = ["apple", "banana", "cherry"]


print(fruits[0]) # Output: apple

Dictionaries
Dictionaries store data in key-value pairs and are unordered and changeable.

Example:

person = {
"name": "Alice",
"age": 25,
"city": "New York"
}
print(person["name"]) # Output: Alice

File Handling
Python allows you to read and write files using the open() function.

Example:

with open("[Link]", "w") as file:


[Link]("Hello, this is a test file.")

with open("[Link]", "r") as file:


content = [Link]()
print(content)

Printing
The print() function is used to display output in Python.
Example:

print("Hello, World!") # Output: Hello, World!

Variables
Variables are used to store data values.

Example:

x=5
name = "Alice"
print(x)
print(name)

Conditionals
Conditional statements are used to perform different actions based on different conditions.

Example:

x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is 5 or less")

Loops
Loops are used to execute a block of code repeatedly.

Example:

for i in range(5):
print(i)

Functions
Functions are blocks of code that run when called and can accept parameters.

Example:

def greet(name):
print("Hello, " + name)
greet("Alice")
Lists
Lists are used to store multiple items in a single variable.

Example:

fruits = ["apple", "banana", "cherry"]


print(fruits[0]) # Output: apple

Dictionaries
Dictionaries store data in key-value pairs and are unordered and changeable.

Example:

person = {
"name": "Alice",
"age": 25,
"city": "New York"
}
print(person["name"]) # Output: Alice

File Handling
Python allows you to read and write files using the open() function.

Example:

with open("[Link]", "w") as file:


[Link]("Hello, this is a test file.")

with open("[Link]", "r") as file:


content = [Link]()
print(content)

Printing
The print() function is used to display output in Python.

Example:

print("Hello, World!") # Output: Hello, World!


Variables
Variables are used to store data values.

Example:

x=5
name = "Alice"
print(x)
print(name)

Conditionals
Conditional statements are used to perform different actions based on different conditions.

Example:

x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is 5 or less")

Loops
Loops are used to execute a block of code repeatedly.

Example:

for i in range(5):
print(i)

Functions
Functions are blocks of code that run when called and can accept parameters.

Example:

def greet(name):
print("Hello, " + name)
greet("Alice")

Lists
Lists are used to store multiple items in a single variable.

Example:
fruits = ["apple", "banana", "cherry"]
print(fruits[0]) # Output: apple

Dictionaries
Dictionaries store data in key-value pairs and are unordered and changeable.

Example:

person = {
"name": "Alice",
"age": 25,
"city": "New York"
}
print(person["name"]) # Output: Alice

File Handling
Python allows you to read and write files using the open() function.

Example:

with open("[Link]", "w") as file:


[Link]("Hello, this is a test file.")

with open("[Link]", "r") as file:


content = [Link]()
print(content)

Printing
The print() function is used to display output in Python.

Example:

print("Hello, World!") # Output: Hello, World!

Variables
Variables are used to store data values.

Example:
x=5
name = "Alice"
print(x)
print(name)

Conditionals
Conditional statements are used to perform different actions based on different conditions.

Example:

x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is 5 or less")

Loops
Loops are used to execute a block of code repeatedly.

Example:

for i in range(5):
print(i)

Functions
Functions are blocks of code that run when called and can accept parameters.

Example:

def greet(name):
print("Hello, " + name)
greet("Alice")

Lists
Lists are used to store multiple items in a single variable.

Example:

fruits = ["apple", "banana", "cherry"]


print(fruits[0]) # Output: apple
Dictionaries
Dictionaries store data in key-value pairs and are unordered and changeable.

Example:

person = {
"name": "Alice",
"age": 25,
"city": "New York"
}
print(person["name"]) # Output: Alice

File Handling
Python allows you to read and write files using the open() function.

Example:

with open("[Link]", "w") as file:


[Link]("Hello, this is a test file.")

with open("[Link]", "r") as file:


content = [Link]()
print(content)

Printing
The print() function is used to display output in Python.

Example:

print("Hello, World!") # Output: Hello, World!

Variables
Variables are used to store data values.

Example:

x=5
name = "Alice"
print(x)
print(name)

Conditionals
Conditional statements are used to perform different actions based on different conditions.

Example:

x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is 5 or less")

Loops
Loops are used to execute a block of code repeatedly.

Example:

for i in range(5):
print(i)

Functions
Functions are blocks of code that run when called and can accept parameters.

Example:

def greet(name):
print("Hello, " + name)
greet("Alice")

Lists
Lists are used to store multiple items in a single variable.

Example:

fruits = ["apple", "banana", "cherry"]


print(fruits[0]) # Output: apple

Dictionaries
Dictionaries store data in key-value pairs and are unordered and changeable.
Example:

person = {
"name": "Alice",
"age": 25,
"city": "New York"
}
print(person["name"]) # Output: Alice

File Handling
Python allows you to read and write files using the open() function.

Example:

with open("[Link]", "w") as file:


[Link]("Hello, this is a test file.")

with open("[Link]", "r") as file:


content = [Link]()
print(content)

Printing
The print() function is used to display output in Python.

Example:

print("Hello, World!") # Output: Hello, World!

Variables
Variables are used to store data values.

Example:

x=5
name = "Alice"
print(x)
print(name)
Conditionals
Conditional statements are used to perform different actions based on different conditions.

Example:

x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is 5 or less")

Loops
Loops are used to execute a block of code repeatedly.

Example:

for i in range(5):
print(i)

Functions
Functions are blocks of code that run when called and can accept parameters.

Example:

def greet(name):
print("Hello, " + name)
greet("Alice")

Lists
Lists are used to store multiple items in a single variable.

Example:

fruits = ["apple", "banana", "cherry"]


print(fruits[0]) # Output: apple

Dictionaries
Dictionaries store data in key-value pairs and are unordered and changeable.

Example:

person = {
"name": "Alice",
"age": 25,
"city": "New York"
}
print(person["name"]) # Output: Alice

File Handling
Python allows you to read and write files using the open() function.

Example:

with open("[Link]", "w") as file:


[Link]("Hello, this is a test file.")

with open("[Link]", "r") as file:


content = [Link]()
print(content)

Printing
The print() function is used to display output in Python.

Example:

print("Hello, World!") # Output: Hello, World!

Variables
Variables are used to store data values.

Example:

x=5
name = "Alice"
print(x)
print(name)

Conditionals
Conditional statements are used to perform different actions based on different conditions.

Example:
x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is 5 or less")

Loops
Loops are used to execute a block of code repeatedly.

Example:

for i in range(5):
print(i)

Functions
Functions are blocks of code that run when called and can accept parameters.

Example:

def greet(name):
print("Hello, " + name)
greet("Alice")

Lists
Lists are used to store multiple items in a single variable.

Example:

fruits = ["apple", "banana", "cherry"]


print(fruits[0]) # Output: apple

Dictionaries
Dictionaries store data in key-value pairs and are unordered and changeable.

Example:

person = {
"name": "Alice",
"age": 25,
"city": "New York"
}
print(person["name"]) # Output: Alice
File Handling
Python allows you to read and write files using the open() function.

Example:

with open("[Link]", "w") as file:


[Link]("Hello, this is a test file.")

with open("[Link]", "r") as file:


content = [Link]()
print(content)

Printing
The print() function is used to display output in Python.

Example:

print("Hello, World!") # Output: Hello, World!

Variables
Variables are used to store data values.

Example:

x=5
name = "Alice"
print(x)
print(name)

Conditionals
Conditional statements are used to perform different actions based on different conditions.

Example:

x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is 5 or less")
Loops
Loops are used to execute a block of code repeatedly.

Example:

for i in range(5):
print(i)

Functions
Functions are blocks of code that run when called and can accept parameters.

Example:

def greet(name):
print("Hello, " + name)
greet("Alice")

Lists
Lists are used to store multiple items in a single variable.

Example:

fruits = ["apple", "banana", "cherry"]


print(fruits[0]) # Output: apple

Dictionaries
Dictionaries store data in key-value pairs and are unordered and changeable.

Example:

person = {
"name": "Alice",
"age": 25,
"city": "New York"
}
print(person["name"]) # Output: Alice

File Handling
Python allows you to read and write files using the open() function.

Example:
with open("[Link]", "w") as file:
[Link]("Hello, this is a test file.")

with open("[Link]", "r") as file:


content = [Link]()
print(content)

Printing
The print() function is used to display output in Python.

Example:

print("Hello, World!") # Output: Hello, World!

Variables
Variables are used to store data values.

Example:

x=5
name = "Alice"
print(x)
print(name)

Conditionals
Conditional statements are used to perform different actions based on different conditions.

Example:

x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is 5 or less")

Loops
Loops are used to execute a block of code repeatedly.

Example:
for i in range(5):
print(i)

Functions
Functions are blocks of code that run when called and can accept parameters.

Example:

def greet(name):
print("Hello, " + name)
greet("Alice")

Lists
Lists are used to store multiple items in a single variable.

Example:

fruits = ["apple", "banana", "cherry"]


print(fruits[0]) # Output: apple

Dictionaries
Dictionaries store data in key-value pairs and are unordered and changeable.

Example:

person = {
"name": "Alice",
"age": 25,
"city": "New York"
}
print(person["name"]) # Output: Alice

File Handling
Python allows you to read and write files using the open() function.

Example:

with open("[Link]", "w") as file:


[Link]("Hello, this is a test file.")

with open("[Link]", "r") as file:


content = [Link]()
print(content)

Printing
The print() function is used to display output in Python.

Example:

print("Hello, World!") # Output: Hello, World!

Variables
Variables are used to store data values.

Example:

x=5
name = "Alice"
print(x)
print(name)

Conditionals
Conditional statements are used to perform different actions based on different conditions.

Example:

x = 10
if x > 5:
print("x is greater than 5")
else:
print("x is 5 or less")

Loops
Loops are used to execute a block of code repeatedly.

Example:

for i in range(5):
print(i)
Functions
Functions are blocks of code that run when called and can accept parameters.

Example:

def greet(name):
print("Hello, " + name)
greet("Alice")

Lists
Lists are used to store multiple items in a single variable.

Example:

fruits = ["apple", "banana", "cherry"]


print(fruits[0]) # Output: apple

Dictionaries
Dictionaries store data in key-value pairs and are unordered and changeable.

Example:

person = {
"name": "Alice",
"age": 25,
"city": "New York"
}
print(person["name"]) # Output: Alice

File Handling
Python allows you to read and write files using the open() function.

Example:

with open("[Link]", "w") as file:


[Link]("Hello, this is a test file.")

with open("[Link]", "r") as file:


content = [Link]()
print(content)

You might also like