Data Types
A Set is an unordered collection data type that is iterable, mutable and has no duplicate elements. Python’s set class represents the mathematical notion of a set. The major advantage of using a set, as opposed to a list, is that it has a highly optimized method for checking whether a specific element is contained in the set. This is based on a data structure known as a hash table.
The Syntax of the set is :
Define: a={Elements of set}
Example: a={1,2,3,4}
print(a)
Warning: Please, always maintain the Indentation, as Python is too much sensitive about the Indentation(maintain the braces in the program Step by Step) Otherwise it will Throw an Error: "Indentation Error".
A Tuple is a collection of Python objects separated by commas. In some ways, a tuple is similar to a list in terms of indexing, nested objects, and repetition but a tuple is immutable, unlike lists which are mutable.
The Syntax of the Tupple is :
Define: a=(Elements of tupple)
Example: a=(1,2,3,4)
print(a)
Boolean values are the two constant objects False and True. They are used to represent truth values (although other values can also be considered false or true).
Example: a=True
print(a)
a=False
print(a)
Lists are one of the most powerful tools in Python. They are just like the arrays declared in other languages. But the most powerful thing is that list need not be always homogeneous. A single list can contain strings, integers, as well as objects. Lists can also be used for implementing stacks and queues. Lists are mutable, i.e., they can be altered once declared.
The Syntax of the List is :
Define: a=[Elements of list]
Example: a=[1,2,3,4,5]
print(a)
In python, a dictionary is similar to hash or maps in other languages. It consists of key-value pairs. The value can be accessed by a unique key in the dictionary.
The Syntax of the Dictionary is :
Define: a={Keys of Element:Elements of Dictionary}
Example: a={1:2,3:4,5:6,7:8}
print(a[1],a[3],a[5],a[7])
#Above will Print the Elements
print(a)
#Above will Print the Entire Dictionary
Python has a built-in method called a type which generally comes in handy while figuring out the type of variable used in the program in the runtime.
The Syntax of the Type Keyword :
Define: type(Object)
Example: a={1:2,3:4,5:6,7:8}
print(Type(a))
#Output : "Dict"
badhiya banaya h bhai... ��
ReplyDeleteShukriya bhai
Delete