Python Tokens

Basically, python tokens are the small units of the programming language. Python supports 4 types of Tokens


Keywords :

These are the dedicated words that have special meaning and functions. Moreover, compiler defines these words. Moreover,  it does not allow users to use these words.. Python compiler has the following words

Identifiers :

Identifiers represent the programmable entities. The programmable entities include user-defined names, variables, modules, and other objects. Moreover, python defines some rules in defining the identifiers. Now let us discuss some of them.

An identifier can be a sequence of lower case (or) upper case (or) integers (or) a combination of any.

The identifier name should start with the lower case (or) upper case (It must not start with digits)

The identifier name should not be a reserved word.

Only Underscore (_) is allowed to use as a special character in identifier names.

The length of the identifier name should not be more than 79 characters

Would you like to know how Machine learning using python

Literals :

Literals are used to define the data as a variable (or ) constants. Python has 6 literals tokens.

String :

The string is a sequence of characters defined between quotes. (both single and double quotes are applicable to define the string literals.). And these strings perform several operations let us discuss some of them.

Syntax Operation
Len(String_name) String length
String_name.index(char) Locate the character in the string
String_name[::-1] Reverse the string
String_name.upper() Converts the strings to upper case
String-name.lower Coverts the string to lower case


These are immutable (unchangeable ) literals. We basically have 3 different numerical types namely integer, float, and complex


This has only two values. i.e true / false.

Collection literals :

A collection literal is a syntactic expression form that evaluates to an aggregate type such as array list (or) Map. Python supports 2 types of collection literal tokens

List Literals :

You can consider the python lists as arrays in C. But the difference between the Arrays and lists is that arrays hold homogeneous data type and lists holds the heterogeneous data types. Basically, this list is the most versatile data type in python. Python literals are separated by a comma in []

Note :

If a comma is not provided between the values, the output does not contain spaces

Example :

List = [‘a’,’b’,’c’]


Output :


The other possible outputs are shown below

Code Output Explanation
List [‘a’,’b’,’c’] This would print all the input values
List[0] A Like arrays, the index of the elements starts with 0
List[2]=’d’ [‘a’,’b’,’d’] It will update the list at index[2] by d with c
Del list[1] [‘a’, ’d’] It would delete the value at index [1]
Len(list) 2 It  returns the length of the tuple
List*2 [‘a’, ’d’]

[‘a’, ’d’]

It prints the output as the number of times the input was given
List[::-1] [‘d’,’a’] It would print the result in the reverse order.

Tuples :

Tuples were similar to list. But like list tuples cannot change the values. Beside, tuples are enclosed in parenthesis. whereas lists are enclosed in square brackets.

And as said earlier, these tuples performs all the operations like lists. So I would like to leave the operation for you as a practice. And if you struck up anywhere clarify at python training.

Set :

A set is a well-defined collection of elements.  And the elements in the set are placed in curly braces separated by a comma. In the set every element is unique

Set 1 = {1 , 2,3}

Set 2  = { 1 , 2, 2 , 3}

In the above example the element 2 is taken twice. Now let us discuss the various set operation



It combines all the elements in the string. And the union operation performed using the pipe (|) operator tokens.

Ex : A = {1,2,3,4,5,6}

B={3,4,5,6 ,7,8}

A|B = {1,2,3,4,5,6,7,8}

Intersections :

Intersection of A and B returns the common elements in the sets . And the operation is performed using the & operator tokens.

Ex : A = {1,2,3,4,5,6}

B={3,4,5,6 ,7,8}

A &B = {3,4,5,6}

Difference :

Difference of (A-B) returns the elements that are only in A but not in B. Similarly B-A returns only the elements that are only in B but not in A tokens.

Ex : A = {1,2,3,4,5,6}

B={3,4,5,6 ,7,8}

A –B = {1,2}

B-A = {7,8}

Symmetric difference :

It returns the set of elements that are both in A and B Except the common elements tokens.

Ex : A = {1,2,3,4,5,6}

B={3,4,5,6 ,7,8}

A^B ={1,2,7,8}

Dictionaries :

Python dictionaries are the key value pairs that are enclosed in curly braces.dictionaries are separated by the “:”

Dict = {‘name’ : ‘Onlineitguru’, age : 20 }

And these elements accessed as Dict[‘name’]

Output: Onlineitguru

Appending the elements in Dictionaries :


Output :

‘name’=’onlineitguru’,’age’=20, address’=ameerpet.

to our newsletter

Drop Us A Query

Trending Courses
  • Pega testing training
    PEGA Testing Training
  • Today application testing is the deciding factor to launch the application into the market. And people do not launch the application unless it goes true.

  • blockchain course
    Blockchain Online Course
  • Today many people were enthusiastic, to know the exact details of things happening around him. This can get the proper knowledge on Blockchain.

  • ethical hacking course
    Ethical Hacking Certification Course
  • Zeal to learn ethical hacking is common among college students and IT professionals. Because everybody wants to secure their system from cyber attacks.

  • python training
    Python Online Training
  • Python is a dynamic interrupted language which is used in wide varieties of applications. It is very interactive object oriented and high-level programming language.

  • Tableau Training
    Tableau Training
  • Tableau is a Software company that caters interactive data visualization products that provide Business Intelligence services. The company’s Head Quarters is in Seattle, USA.

  • what is pega
    PEGA Online Training
  • Pega Systems Inc. is a Cambridge, Massachusetts based Software Company. It is known for developing software for Customer Relationship Management (CRM) and Business process Management (BPM).

100% Secure Payments. All major credit & debit cards accepted.