0% found this document useful (0 votes)
2 views24 pages

Python Language

This document is a lecture on Python fundamentals, focusing on the print statement, variables, data types, and user input. It covers how to display output, create variables, work with different data types, and take user input using the input() function. The lecture includes hands-on practice and assessments to reinforce learning.

Uploaded by

hafsa2004arshad
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)
2 views24 pages

Python Language

This document is a lecture on Python fundamentals, focusing on the print statement, variables, data types, and user input. It covers how to display output, create variables, work with different data types, and take user input using the input() function. The lecture includes hands-on practice and assessments to reinforce learning.

Uploaded by

hafsa2004arshad
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

>_ python

PYTHON FOR BEGINNERS

Python Fundamentals
Lecture 2 · Print Statement, Variables, Data Types & Input / Output

Print Statement Variables Data Types Input & Output Hands-on Practice

Python Fundamentals · Lecture 2 01 / 23


LECTURE 2 · OVERVIEW >_
Learning Objectives
By the end of this lecture, students will be able to:

Display output Create variables


✓ Show results on screen using the print() function ✓ Store and reuse data with named variables

Use data types Take user input


✓ Work with int, float, str and bool values ✓ Read data from users with input()

Build programs Predict → Run → Explain


✓ Combine it all into simple interactive apps
The learning rhythm we'll use in every demo

Python Fundamentals · Lecture 2 02 / 23


OUTPUT · PRINT() >_
What is Output?

Output means displaying


print("Hello World")
information to the user.
Python uses the print() function to send text
and values to the screen.
OUTPUT

Hello World

Your first Python command

Python Fundamentals · Lecture 2 03 / 23


OUTPUT · SYNTAX >_
Understanding print()
SYNTAX
Without print()

print(object)
5 + 5

→ Nothing appears
Why do we use print()?
With print()
Calculations run, but nothing shows unless you print
the result.
print(5 + 5) 10

Python Fundamentals · Lecture 2 04 / 23


OUTPUT · CONCEPT >_
Behind the Scenes

Python Built-in Operating


Your Code → → → → Terminal
Interpreter print() System

Parentheses ( ) run the Output travels to the


1 print() is a built-in function 2 function
3 terminal
Always available — no import needed. They tell Python to execute print now. Python hands the text to your system.

Python Fundamentals · Lecture 2 05 / 23


OUTPUT · PRACTICE >_
Live Coding

print("Hello")
print("Pakistan") ?
print(50)
print(5 + 10) Predict the output
print("5+10")
print(True)
print(False)

Quotes vs. no quotes

Python Fundamentals · Lecture 2 06 / 23


OUTPUT · FORMATTING >_
More Examples

print("Ali") Multiple arguments


print("Ali", "Ahmed") Separate values with commas — print adds
print("Python", "Java", "C++") a space between them.

print("Python\nProgramming")
print("Ali\tAhmed")
New line \n
Breaks the text onto the next line.

Tab \t
Inserts a horizontal tab space.

Python Fundamentals · Lecture 2 07 / 23


OUTPUT · DEBUGGING >_
Common Mistakes

✕ WRONG ✕ WRONG ✕ WRONG

Print("Hello") print(Hello) print "Hello"

Wrong capital P Missing quotes No parentheses


Python is case-sensitive — use Text must be inside quotation print is a function — it needs ( ).
lowercase print. marks.

Python Fundamentals · Lecture 2 08 / 23


VARIABLES · CONCEPT >_
Variables
IN MEMORY

What is a Variable?
name
A variable is a named container used to store
data in memory.

"Ali"

name = "Ali" ↓
The label 'name' points to the value stored
inside.

Python Fundamentals · Lecture 2 09 / 23


VARIABLES · MOTIVATION >_
Why Variables?

Without variables With variables

print("Ali") name = “laiba noor"


print("Ali") print(name)
print("Ali") print(name)
print(name)

Repeating the value everywhere — hard to change. Change it once — every use updates.

✓ Reusable ✓ Easy to update ✓ Easy to maintain

Python Fundamentals · Lecture 2 10 / 23


VARIABLES · SYNTAX >_
Creating Variables

Every variable has three parts:


name = "Ali"
age = 20
Variable name name
cgpa = 3.82 1 The label you choose
is_student = True

Assignment operator =
2 Stores the value into the name

Value "Ali"
3 The data being stored

Python Fundamentals · Lecture 2 11 / 23


VARIABLES · RULES >_
Variable Naming Rules

✓ ALLOWED ✕ NOT ALLOWED

Letters Numbers Underscore _ Start with number Spaces Keywords

Good examples Bad examples

student_name 2name
first_name my name
total_marks for

Python Fundamentals · Lecture 2 12 / 23


VARIABLES · RULES >_
Reserved Words

Python Fundamentals · Lecture 2 12 / 23


DATA TYPES · CORE FOUR >_
Data Types

int 20 float 3.75

Whole numbers Decimal numbers


e.g. Age, count of items e.g. CGPA, price, weight

str "Ali" bool True

Text in quotes True or False


e.g. Names, messages e.g. Yes/no, on/off states

Python Fundamentals · Lecture 2 13 / 23


DATA TYPES · TYPE() >_
Checking Data Types
Use type() to ask Python what kind of value a variable holds.

name = "Ali" age = 20


print(type(name)) print(type(age))

<class 'str'> output <class 'int'> output

cgpa = 3.82 is_student = True


print(type(cgpa)) print(type(is_student))

<class 'float'> output <class 'bool'> output

Python Fundamentals · Lecture 2 14 / 23


INPUT · INPUT() >_
Input
SYNTAX

Input means taking data from the variable = input("Message")


user.
Python uses the input() function to pause
and wait for the user to type. EXAMPLE

name = input("Enter your name


: ")

The program waits for you Whatever the user types is stored in the variable.

Python Fundamentals · Lecture 2 15 / 23


INPUT · INTERACTION >_
Input + Output
FLOW

name = input("Enter Name: ")


User
print("Welcome", name)

input()

Variable

The program greets the user by name — a two-way print()


conversation between you and Python. ↓
Output

Python Fundamentals · Lecture 2 16 / 23


INPUT · TYPE CONVERSION >_
Very Important

! Everything from input() is a String — even numbers.

CONVERT TO NUMBERS
age = input("Age: ")
print(type(age)) age = int(input("Age: "))

price = float(input("Price: "))


<class 'str'>
int() for whole numbers, float() for decimals.

Python Fundamentals · Lecture 2 17 / 23


HANDS-ON · MINI PROJECT >_
Student Registration System
Take these inputs from the user: DISPLAY

1 Name ========= Student Card =========

Name :
2 Age Age :
University :
3 University Department :
Semester :

4 Department
================================

5 Semester

Python Fundamentals · Lecture 2 18 / 23


HANDS-ON · PRACTICE >_
Hands-on Practice

EASY MEDIUM ADVANCED

• Print your name • Student Card • Calculator


• Print your city • Country + City • Age Calculator
• Store your age • Marks • Student Profile
• Print favourite food • CGPA

Python Fundamentals · Lecture 2 19 / 23


ASSESSMENT · QUIZ >_
Predict the Output

1 Question 1 2 Question 2 3 Question 3

print("5+5") print(5 + 5) name = "Ali"


print(name)

4 Question 4 5 Question 5

x = 10 age = input("Age:")
print(type(x)) print(age + age)

Python Fundamentals · Lecture 2 20 / 23


ASSESSMENT · CHALLENGE >_
Coding Challenge

Take input for:

Personal Profile Program 1 Name

Build a program that collects a user's details and 2 Age


prints them in a clean, professional format.
3 City

4 Favourite Programming Language

5 University
Uses input, variables & print

6 CGPA

Python Fundamentals · Lecture 2 21 / 23


ASSESSMENT · HOMEWORK >_
Homework

Task 1 TASK 1 Task 2 TASK 2 Task 3

Student Information Favourite Movie


System Program

Collect and display a student's full Ask about a favourite movie and
details using input and print. present the answers nicely.

Python Fundamentals · Lecture 2 22 / 23


LECTURE 2 · RECAP >_
Summary
Today we learned:

print() Variables Data Types


✓ Display output ✓ Store data ✓ int, float, str, bool

type() input() Practice


✓ Check a value's type ✓ Read from users ✓ Hands-on programs

Python Fundamentals · Lecture 2 23 / 23

You might also like