Basic Fundamentals:
The basic fundamentals of Python like :
i)Tokens and their types.
ii) Comments
a)Tokens:
- A reserved word known as a tokens that can be defined as punctuator mark.
- Token is the smallest unit inside the given program.
- There are following tokens in Python:
Keywords.
Identifiers.
Literals.
Operators.
Tuples:
- Tuple is another form of collection where different type of data can be stored.
- It is similar to list where data is separated by ,(commas). Only the difference is that list uses [] (square bracket) and truple uses ()(parenthesis).
- Tuples are enclosed in parenthesis and cannot be changed.
Eg:
tuple=('python',200,70.5,'basic')
tuple1=('fundamentals',20)
Above is a declaration of truple there are tow variable in truple truple and tuple1.
Outputs :
- when you write in the console truple then it display all truple value.
like :
tuple
('python',200,70.5,'basic')
- when you want a specific position data and after position all data then write a variable name and its value position and after that put a : (colon) sign
like :
tuple[2:] (truple(name of the variable)[2(it is a position of variable):(it is like a * after position all data print)])
(70.5, 'basic')
- when you know the what position data you want that time use this variable name [ position of data ]
like :
tuple1[0]
'fundamentals'
collaboration of two truples
- using +(plus)sign you can collaborate two or more truples.
like :
tuple+tuple1
('python',200,70.5,'basic','fundamentals',20)
Dictionary:
Dictionary is a collection which works on a key-value pair.
It works like an associated array where no two keys can be same.
Dictionaries are enclosed by {} (curly braces) and values can be retrieved by [] (square bracket).
Syntax :
variable name =(equal sign) {'key':(colon)'value }
Like :
Deceleration : dictionary={'name':'abc','id':500,'dept':'ec'}
Input : dictionary
Output :{'dept': 'ec', 'name': 'abc', 'id': 500} (It display output after sorting)
Input : dictionary.keys() (if you want only keys then write a variable name .(dot) keys())
Output: ['dept', 'name', 'id']
Input : dictionary.values() (if you want only values then write a variable name .(dot) values())
Output: ['ec', 'abc', 500]
ii) Comments :
python support two types of comments.
1) single line comments :
single line comments start with # sign.
like #comments
2) Multi line Comments :
Multi lined comment can be given inside triple quotes.
like :
'''multi line
comment '''
No comments:
Post a Comment