• Tutorials Logic, IN
  • +91 8092939553
  • info@tutorialslogic.com

Data Types and Keywords in Python

Data Types

Python is a dynamically typed language, so we don't need to specify the type of the variable while declaring it. The Python interpreter implicitly binds the value with its type. Python provides the type() method which returns the type of the variable. Python has the following data types-

Numbers:- It is used to store numerical values as well as to carry out the normal mathematical operations. Numbers can be defined as int, float and complex data types in Python.

										    
											x = 5
											print(type(x)) # int
											
											y = 2.0
											print(type(y)) # float
											
											z = 1+2j
											print(type(z)) # complex
											
										

Strings:- String is a sequence of Unicode characters. We can use single quotes or double quotes to represent strings. It is used to store textual information.

										    
											x = 'Tutorials Logic'
											print(type(x)) # str
											
										

Lists:- It is the most generic data type in Python. Lists can consist of a collection of mixed data types, separated by commas and enclosed within square brackets ([ ]).

										    
											list = [ 'Tutorials Logic', 777 , 7.77 ]
											print(type(list)) # list
											
										

Tuples:- Tuple is an ordered sequence of items, that are similar to the list. It can consist of a collection of mixed data types, separated by commas and enclosed within parentheses ( ). Tuples are faster than list as once it is created can't be modified.

										    
											tuple = ( 'Tutorials Logic', 777 , 7.77 )
											print(type(tuple)) # tuple
											
										

Sets:- It is an unordered and unindexed collection of unique items, separated by commas and enclosed within curly brackets { }.

										    
											set = { 'Tutorials Logic', 777 , 7.77 }
											print(type(set)) # set
											
										

Dictionaries:- It is an unordered, changeable and indexed collection with pair of keys and values. It can store multiple objects, separated by commas and enclosed within curly brackets { }.

										    
											dictionary = {
												'name': 'Tutorials Logic',
												'year': 1964
											}
											print(type(dictionary)) # dict
											
										

Keywords

Python keywords are reserved words, which we cannot use as a variable names, function names, or any other identifiers. Python has below list of keywords-

Keyword
andasassertbreak
continueclassdefdel
elifelseexceptFalse
finallyforfromglobal
ifimportinis
lambdaNonenonlocalnot
orpassraisereturn
Truetrywhilewith
yield---