Free Python Course
Kanalga Telegram’da o‘tish
Ko'proq ko'rsatish
5 967
Obunachilar
Ma'lumot yo'q24 soatlar
-357 kun
-22530 kun
Postlar arxiv
5 967
EXAMPLE 8 : PYTHON LIST INSIDE TUPLE
data = ( 1 , "Rushi" , 8.0 , ["Rushi" , "Lade" , 16], "RL")
print(data)
Output:
(1, 'Rushi', 8.0, ['Rushi', 'Lade', 16], 'RL')5 967
EXAMPLE 7 : TUPLE WITH ONE ELEMENT
nums = (1) # this is not tuple
nums1 = (1,) # this is tuple
print(type(nums))
print(type(nums1))
name = ('Rushi') # this is not tuple
name1 = ('Rushi',) # this is tuple
print(type(name))
print(type(name1))
Output:
<class 'int'>
<class 'tuple'>
<class 'str'>
<class 'tuple'>5 967
EXAMPLE 6 : PYTHON TUPLE LEN()
data = ( 1 , "Rushi" , 8.0 )
print(len(data))
Output:
35 967
EXAMPLE 5 : CREATING TUPLE USING RANGE () FUNCTION
data = tuple(range(0,10,1))
print(data)
Output:
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)5 967
EXAMPLE 4 : TUPLE SLICING
data = ( 1 , "Rushi" , 8.0 )
print(data[0:2])
Output:
(1, 'Rushi')5 967
EXAMPLE 3 : TUPLE INDEXING
data = ( 1 , "Rushi" , 8.0 )
print(data[1])
Output:
Rushi5 967
EXAMPLE 2 : PRINT TUPLE DATA WITH FOR LOOP
data = ( 1 , "Rushi" , 8.0 )
for i in data:
print(i)
Output:
1
Rushi
8.05 967
EXAMPLE 1 : CREATING A TUPLE
data = ( 1 , "Rushi" , 8.0 )
print(data)
Output:
(1, 'Shani', 8.0)5 967
WHAT IS TUPLE ?
• Python Tuple is a collection of objects separated by commas.
• Tuples are used to store multiple items in a single variable.
• Tuple is one of 4 built-in data types in Python used to store collections of data, the other 3 are List, Set, and Dictionary, all with different qualities and usage.
• A tuple is a collection which is ordered and Immutable (unchangeable).
• Tuples are written with round brackets.
5 967
DICTIONARY VALUES METHOD :
data = {"Name": "Rushi" , "Age": 16}
x = data.values()
print(x)
Output:
dict_values(['Rushi', 16])5 967
DICTIONARY UPDATE METHOD :
data = {"Name": "Rushi","Age": 16}
data.update({"Status" : "Programmer"})
print(data)
Output:
{'Name': 'Shani', 'Age': 19, 'Status': 'Programmer'}5 967
DICTIONARY SETDEFAULT METHOD :
data = {"Name": "Rushi" , "Age": 16}
x = data.setdefault("Name","CodeWithRushi")
print(x)
Output:
Rushi
5 967
DICTIONARY POPITEM METHOD :
data = {"Name": "Rushi","Age": 16}
data.popitem()
print(data)
Output:
{'Name': 'Shani'}5 967
DICTIONARY POP METHOD :
data = {"Name": "Rushi","Age": 16}
data.pop("Name")
print(data)
Output:
{'Age': 16}5 967
DICTIONARY KEYS METHOD :
data = {"Name": "Rushi","Age": 16}
x = data.keys()
print(x)
Output:
dict_keys(['Name', 'Age'])5 967
DICTIONARY ITEMS METHOD :
data = {"Name": "Rushi","Age": 16}
x = data.items()
print(x)
Output:
dict_items([('Name', 'Rushi'), ('Age', 16)])5 967
DICTIONARY GET METHOD :
data = {"Name": "Rushi","Age": 16}
x = data.get("Name")
print(x)
Output:
Rushi5 967
DICTIONARY FROMKEYS METHOD :
x = ('key1', 'key2', 'key3')
y = 10
thisdict = dict.fromkeys(x, y)
print(thisdict)
Output:
{'key1': 10, 'key2': 10, 'key3': 10}