Python Tokens

Click to rate this post!
[Total: 12 Average: 3.6]

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
  • oracle 12c rac | OnlineITGuru
    Oracle RAC Training
  • Oracle is the large vendor in providing the various storge services to the people across the globe. This vendor provides a different amount of storage services to the people across the globe.

  • salesforce lightning training | OnlineITGuru
    Salesforce Lightning Training
  • Developing an application is not a simple and easy task. There are various parameters that the web developer need to take care while developing an application. One of those parameters that the developer needs to take care of is the code reusability.

  • Selenium with python
    Selenium with Python Training
  • As we know, that Selenium with Python Web Browser Selenium Automation is Gaining Popularity Day by Day. So many Frameworks and Tools Have arisen to get Services to Developers.

  • machine learning with python
    Machine Learning with Python Training
  • Over last few years, Big Data and analysis have come up, with Exponential and modified Direction of Business. That operate Python, emerged with a fast and strong Contender for going with Predictive Analysis.

  • Data science with R
    Data Science With R Training
  • Understanding and using Linear, non-linear regression Models and Classifying techniques for stats analysis. Hypothesis testing sample methods, to get business decisions.

  • data science with python
    Data Science with Python Training
  • Everyone starts Somewhere, first you learn basics of Every Scripting concept. Here you need complete Introduction to Data Science python libraries Concepts.

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

Call Now Button