Lecture No 7
Lecture No 7
Introduction to
Python
Variable Names:
• Variable names with more than one word can be difficult to read.
• There are several techniques you can use to make them more readable:
• And you can assign the same value to multiple variables in one line
x = y = z = "Orange“
• Unpack a Collection:
• If we have a collection of values in a list, tuple etc. Python allows us to
extract the values into variables. This is called unpacking.
fruits = ["apple", "banana", "cherry"]
x, y, z = fruits
x=5
y = "John"
May 14, 2024 print(x, y) 12
Python Variables
• Global Variables
• Variables that are created outside of a function (as in all of the examples above) are known as global variables.
• Global variables can be used by everyone, both inside of functions and outside.
• To change the value of a global variable inside a function, refer to the variable by
using the global keyword
There are four collection data types in the Python programming language:
List is a collection which is ordered and changeable. Allows duplicate members.
Tuple is a collection which is ordered and unchangeable. Allows duplicate members.
Set is a collection which is unordered, unchangeable*, and unindexed. No duplicate members.
Dictionary is a collection which is ordered** and changeable. No duplicate members.
• Access tuple
• Update tuple
• Unpack
• Join tuple
• Count
• Index