0% found this document useful (0 votes)
11 views3 pages

Python - Colab notes

The document provides an overview of Python, highlighting its features such as simplicity, versatility, and being beginner-friendly. It explains variables in Python, including how to declare and use them, and discusses the print() function and f-strings for output formatting. Additionally, it includes examples demonstrating the use of variables and print statements in Python programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Python - Colab notes

The document provides an overview of Python, highlighting its features such as simplicity, versatility, and being beginner-friendly. It explains variables in Python, including how to declare and use them, and discusses the print() function and f-strings for output formatting. Additionally, it includes examples demonstrating the use of variables and print statements in Python programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

5/20/25, 11:00 PM day1_AnjaliOjha_SeramporeGirlsCollege.

ipynb - Colab

1. What is Python? Explain the features of Python and why it is a popular programming language.

=> Python is a high-level, interpreted programming language known for its simplicity, readability, and versatility. It was created by Guido van
Rossum and first released in 1991.

Some features of Python are as follows:-


Simple and Easy to Learn:- Python has a clean and easy-to-read syntax, which makes it beginner-friendly.
Interpreted Language:- Python is interpreted, meaning code is executed line by line. This helps with debugging and testing.
High-Level Language:- Python abstracts away many complex low-level details, allowing developers to focus on solving problems.
Object-Oriented and Functional:- Supports both object-oriented and functional programming paradigms.

Python is widely popular. Some of the reasons are as follows:-


Versatility:- Used in diverse fields such as web development (Django, Flask), data science (Pandas, scikit-learn), automation (scripts), and AI
(TensorFlow, PyTorch).
Ease of Learning and Use:- Great for beginners, yet powerful enough for experts.
Open Source:- Free to use, with continual improvements by the global community.

2. What are variables in Python? Explain with examples how to declare and use variables in Python.

=> Variables in Python are used to store data values. A variable acts as a symbolic name for a value and allows us to access and manipulate
that value throughout our program.
i. We don’t need to declare the type of a variable (Python is dynamically typed).
ii. A variable is created when we assign a value to it.
iii. Variable names are case-sensitive (name and Name are different).
iv. Must start with a letter or underscore (not a number).
v. Can include letters, digits, and underscores (_).

#This is an example of storing a number in the variable age

age = 25
print(age)

25

#This is an example of storing a string in the variable name

name = "Alice"
print(name)

Alice

#This is an example of using variables in operations

x = 10
y = 5
sum = x + y
print("Sum is:", sum)

Sum is: 15

3. What is the use of the print() function in Python? Give examples using print() to display text, numbers, and variables.

=> The print() function in Python is used to display output on the screen. It sends data (text, numbers, variables, etc.) to the standard output
device, usually the console or terminal.
Key Uses of print():-
i. Displaying text messages.
ii. Showing the values of variables.
iii. Printing results of expressions.
iv. Combining strings and variables for readable output.

#This is an example of print() to display text

print("Hello, Python!")

Hello, Python!

https://colab.research.google.com/drive/13um1p86Dqbo-IbflSYyQZ8bWt6u_5yli#scrollTo=swDaV-evqLB5&printMode=true 1/3
5/20/25, 11:00 PM day1_AnjaliOjha_SeramporeGirlsCollege.ipynb - Colab
#This is an example of print() to display numbers

print(123)
print(3.14)

123
3.14

#This is an example of print() to display variables

name = "Alice"
age = 25
print(name)
print(age)

Alice
25

4. What is an f-string in Python? Explain f-strings and give examples of how they are used to format strings with variables.

=> An f-string (formatted string literal) is a way to embed expressions (like variables) directly inside string literals using a concise and
readable syntax.
Some features of f-string are:-
i. Easy to insert variables into strings.
ii. Supports expressions, not just variables.
iii. More readable and efficient than older methods like str.format() or string concatenation.

#This is an example of using f-strings for inserting variables

name = "Alice"
age = 25
print(f"My name is {name} and I am {age} years old.")

My name is Alice and I am 25 years old.

#This is an example of using f-strings for formatting numbers

pi = 3.14159
print(f"Value of pi: {pi:.2f}")

#Here, :.2f formats the number to 2 decimal places.

Value of pi: 3.14

5. Write a Python program that declares two variables and uses both print() and f-string to display their values.

# Declare variables
name = "Alice"
age = 25

# Using print() with comma-separated values


print("Name:", name)
print("Age:", age)

# Using f-strings to format output


print(f"My name is {name} and I am {age} years old.")

Name: Alice
Age: 25
My name is Alice and I am 25 years old.

https://colab.research.google.com/drive/13um1p86Dqbo-IbflSYyQZ8bWt6u_5yli#scrollTo=swDaV-evqLB5&printMode=true 2/3
5/20/25, 11:00 PM day1_AnjaliOjha_SeramporeGirlsCollege.ipynb - Colab

https://colab.research.google.com/drive/13um1p86Dqbo-IbflSYyQZ8bWt6u_5yli#scrollTo=swDaV-evqLB5&printMode=true 3/3

You might also like