This lesson covers the basics of the print() function, variables, and user input in Python. It explains how to display text and values, the types of variables (integer, float, string, boolean), and how to take user input while converting it to the appropriate data type. Additionally, it includes a mini challenge to reinforce learning by writing a simple program.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
9 views
Python Print Variables Input
This lesson covers the basics of the print() function, variables, and user input in Python. It explains how to display text and values, the types of variables (integer, float, string, boolean), and how to take user input while converting it to the appropriate data type. Additionally, it includes a mini challenge to reinforce learning by writing a simple program.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 27
Lesson 2: Print
Function, Variables, and Input Presented to you by @DeepTV12 The print() Function
The print() function is used to display text and
values on the screen. Example: print('Hello, World!') Printing Numbers
We can print numbers directly without quotes.
Example: print(10) Printing Multiple Items
We can print multiple values using commas.
Example: print('My age is', 21) Printing with Separator
Use 'sep' to change the separator.
Example: print('Python', 'is', 'fun', sep='-') Printing with End
Use 'end' to change how the line ends.
Example: print('Hello', end=' ') print('World!') Understanding Variables in Python What is a Variable?
A variable is like a container that stores data in
memory. Example: x=5 Naming Rules for Variables
Can contain letters, numbers, and underscores
Must start with a letter or underscore Case-sensitive (age and Age are different) easy to read and understand Good example(Id,name1,FirstName,DeepTV 12, Last_Name) Bad examples(1name,First-name, hfkaj675) Integer Variables
Example: x = 10 print(x) x = 20 print(x) x= x*5 print(x) Taking User Input in Python The input() Function
Used to take input from the user.
It will ask users to enter text Example: name = input('Enter your name: ') It will always be a “string” until you change its type Input Always Returns a String Even if the user enters a number, it's stored as text. Example: age = input('Enter your age: ') Converting Input to Integer Use int() to convert input to a number. Example: age = int(input('Enter your age: ')) It will take this string and change it to integer data type Converting Input to Float
Use float() to accept decimal numbers.
Example: height = float(input('Enter height: ')) It will take this string and change it to float Make a python program that asks user for length and width and prints the area of that rectangle (length X width) for example : length = 5 width = 2 area = 10 Answer Mini Challenge Try it yourself! Challenge Instructions
Write a Python program that:
Asks for your name, age, and city Prints them in a sentence Challenge Hint
Use input() to take user input and print() to
display it. Example: name = input('Enter name: ') print('Hello,', name) That’s all for today, you have learn how to print, variables types, how to store a variable, how to take user input, how to change string to another datatypes The most important part for now is to practice and type each code we took today and try to solve the mini challenge YOURSELF Answers will be posted on my telegram channel next to my the slides If you have any questions or errors, you can comment it on my channel Answers will be posted on my telegram channel next to my the slides If you have any questions or errors, you can comment it on my channel Thanks for Watching