Python Programming Powerpoint v[2]
Python Programming Powerpoint v[2]
UNIT -1
BY…..
AISHWARYA.D
Python:
Numbers
Strings
Variables
Lists
Tuples
Dictionaries
Sets
Comparison
Data Structure in Python
NUMBERS
In Python, numbers are a fundamental data type used to represent numerical
values.
Here's a breakdown of the different types of numbers in Python:
1.Integers (int): Represent whole numbers without any fractional component.
Can be positive, negative, or zero.
Examples: 1, -10, 0, 1000000.
2. Floating-Point Numbers (float):
Represent real numbers with a decimal point.
Can be positive, negative, or zero.
Examples: 3.14, -2.718, 0.0.
3. Complex Numbers (complex):
Represent numbers with a real and an imaginary part.
Written in the form a + bj, where a is the real part and b is the imaginary part
and j represents the imaginary unit (√-1).
Arithmetic Operations:
Python supports standard arithmetic operations on numbers,
including addition (+), subtraction (-), multiplication (), division (/),
modulo (%), and exponentiation (*).
STRINGS
String is a collection of one or more character put in a single code, double
code or triple code.
python where is a character data type a character is a string of length
one it is represent by string class.
Example:
String 1 = ‘welcome’
print(“string with the use of single quotes”)
print(string 1)
String 1 =“welcome”
print(“\n string with use of double quotes”)
print(type (string 1))
String 1 =‘“Welcome’’’
print(“\n string with use of Triple quotes”)
print(string 1)
print(type(string 1))
Output:
‘welcome’
“welcome”
‘“welcome’”
Example
1. str = "string using double quotes"
2. print(str)
3. s = '''''A multiline
4. string'''
5. print(s)
Output:
Creating Variables:
Ex: x=5
y=“Hi”
print(x)
print(y)
x=6
print(x)
Output:
Hi
String Variables:
Ex: x=“John”
x=‘John’
Case Sensitive:
Name = “Hello”
Ex: a= 10
b= 5
print(a + b)
Output:
15
Rules for python variable:
Python variable name can only contain alpha numeric characters and
Underscore.
Local Variable
Global Variable
Local Variable:
The variable that are declare with in a function we can’t access variabl
outside the function.
Ex:
def f():
# local variable
s = "I love Geeksforgeeks“
print(s)
# Driver code f()
Output:
I love Geeksforgeeks
Global Variable:
Output
Example:
Create a List:
print(thislist)
Output:
List items are indexed and you can access them by referring to
the index number.
Example:
print(thislist[1])
Output:
Banana
thislist =
["apple", "banana", "cherry"]
thislist[1] = "blackcurrant“
print(thislist)
Output:
Append Items:
To add an item to the end of the list, use the append() method:
Example:
Output:
Example:
Remove "banana":
Output:
['apple', 'cherry']
Copy a List:
You can use the built-in List method copy() to copy a list.
Example:
Output:
Order
Unchangeable
immutable
Allow duplicate value
Allow value with multiple data types.
Ex:
a=(1,2,3,4,5)
print(a)
b=(“hello”,1,2,3,”go”)
print(b)
print(b[4])
Access Tuple Items:
You can access tuple items by referring to the index number, inside
square brackets:
Example:
Print the second item in the tuple:
thistuple = ("apple", "banana", "cherry")
print(thistuple[1])
Output:
Banana
Change Tuple Values:
Once a tuple is created, you cannot change its values. Tuples are
unchangeable, or immutable as it also is called.
Example:
Output:
Output:
first name
last name
33
Boolean Data types:
The boolean value are used to evaluate value of expression. When the
Compare to value the expression is evaluated and python return the boolean
True or false.
Ex: x=25
y=20
z=xyz
print(z)
print(type(z))
Sets in Python
Python set that not maintain the order of element that is an unorder data se
Different ways creating them an adding, updating, removing, the set items.
Ex:
Set ={“apple”,”banana”,”cherry”,True,1,2}
print(set)
Output: {“apple”,”banana”,”cherry”,True,2}
Here's an example:
Python
x = 10
y=5
print(x == y) # False
print(x != y) # True
print(x > y) # True
print(x < y) # False
print(x >= y) # True
print(x <= y) # False
THANK YOU