Python Tokens

Click to rate this post!
[Total: 3 Average: 3]

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

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
tokens

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.
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.count(char)
String_name[::-1] Reverse the string
String_name.upper() Converts the strings to upper case
String-name.lower Coverts the string to lower case

Numeric:

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

Boolean:

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
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’]

Print(list)

Output :

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

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


tokens

Union:

It combines all the elements in the string. And the union operation performed using the pipe (|) operator tokens.
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.
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.
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.
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 :

Dict[‘address’]=ameerpet

Output :

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

Subscribe
to our newsletter

Drop Us A Query

Trending Courses
  • 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.

  • devops with azure
    Devops with Azure Training
  • As we Know Azure DevOps is a Bunch of Services, in guiding Developers. It contains CI/CD, pipelines, code Repositories, Visual Reporting Tools and more code management with version control.

  • python training
    Python Certification 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.


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

Call Now Button