0% found this document useful (0 votes)
17 views10 pages

4 TH

Uploaded by

m.abdullah.pk68
Copyright
© © All Rights Reserved
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% found this document useful (0 votes)
17 views10 pages

4 TH

Uploaded by

m.abdullah.pk68
Copyright
© © All Rights Reserved
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/ 10

AQSA

Department BSCS
Programming Fundamental
Semester 1st
Lecture #4
Topic : Data types in python
Built-in library
Data Type
The concept of a data type in programming is essential because it
determines the kind of data a variable can store and the operations
that can be performed on that data.
• In Python, data types are fundamental because they help the
interpreter allocate memory, decide on operations, and ensure
that data is processed accurately.
Basic Data Types
•Integers (int): Whole numbers, positive or negative, with no
decimal point, e.g., 5, -3.
•Floating-Point Numbers (float): Numbers with a decimal
point, useful for representing real numbers e.g., 3.14, -0.001.
•Booleans (bool): Represents binary values True and False,
often used in conditional statements and logical operations.
Sequence Data Types
•Strings (str): A sequence of characters, enclosed in
single, double, or triple quotes, e.g., 'hello', "Python".
•Lists (list): Ordered, mutable collections that can hold
different data types, e.g., [1, "apple", 3.5].
•Tuples (tuple): Similar to lists but immutable, meaning
once defined, their values cannot change, e.g., (1, 2,
"banana").
Mapping Data Types
•Dictionaries (dict): Key-value pairs, useful for
associating unique keys with values, e.g., {"name":
"Alice", "age": 25}.
Set Data Types
•Sets (set): Unordered collections of unique items, used
for membership testing and removing duplicates, e.g.,
{1, 2, 3, 3} results in {1, 2, 3}.
Variables in a Programming Language

:
In programming, an identifier (or variable) is a name given to a storage location in
memory that holds data, which can be manipulated and used throughout a
program. Variables allow programmers to store, retrieve, and manipulate data
without needing to know the memory location.
Use of Variables in a Programming Language
• Data Storage: Variables temporarily hold data that a program needs to function.
• Readability: Meaningful variable names make code easier to read and understand.
• Reusability and Flexibility: Variables allow data to be reused, modified, and
adapted in different parts of a program without hardcoding values.
• Modularity: Using variables allows for structured and modular code, where values
can be changed in one place and reflected across the program.
Valid Variable :
Defining Valid Variable Names in Python
Python has specific rules for defining valid variable names,
which help prevent errors and make code more readable:
Alphabetic and Numeric Characters
A variable name can contain letters (A-Z, a-z), digits (0-9), and
underscores (_).
python
1variable = 20
No Reserved Keywords
Python has no reserved keywords (like class, if, while,
etc.) that cannot be used as variable names.
python
for = 5
Avoid Special Characters: Variable names cannot
contain spaces or special characters like @, #, $, &, etc.,
except for the underscore
Valid: name, _name, age2, total_sum, max_value
Specifier
Using % Format Specifier
•The % operator allows format specifiers
within a string.
•Common format specifiers include:
%d: Integer
%f: Floating-point number (default 6
decimal places)
%.nf: Floating-point with n decimal places,
%.2f for 2 decimal places
%s: String
Example :
age = 25
name = "Alice"
print("Hello, %s! You are %d years old." % (name, age))

Example 2

name = "Bob“

height = 5.9

print(f"{name} is {height:.1f} feet tall.")


Arithmetic expression and Assignment operator python
In Python, arithmetic expressions involve using
arithmetic operators to perform calculations on values,
while the assignment operator assigns the result of
those expressions (or any value) to a variable.
Arithmetic Operators in Python
Here are the basic arithmetic operators in Python:
Addition (+) Adds two values.
sum = 5 + 3
Arithmetic expression and Assignment operator python
Subtraction Subtracts the second value from the first.
difference = 5 – 3
Multiplication Multiplies two values
product = 5 * 3
Division Divides the first value by the second. Division in Python always
returns a float.
quotient = 5 / 3
Modulus Returns the remainder after division
remainder = 5 % 3
Exponentiation Raises the first value to the power of the second.
power = 5 ** 3
Assignment Operator (=) in Python
The assignment operator = is used to assign values to variables. The
variable on the left of the = operator receives the value on the right
x = 10 # Assigns 10 to x
name = "Alice"

You might also like