Skip to main content

Tokens in Python


Tokens

Tokens are smallest unit of a python program. As we see in chemistry a molecule are made up of combination of elements. Same as we compare in python programming the programs which we write in python are the molecules and the tokens are the elements of python. There are five types of tokens in python:
  • Keywords
  • Identifiers
  • Literals
  • Punctuators
  • Operators

Keywords

Keywords are nothing but the reserved words which are used by python and have their specific meanings. We are not allowed to use keywords as variables in Python. Keywords in python are case sensitive. Some keywords in python are False, None, True, and, if, class, global, else, finally, for, not, etc.

Identifiers

Identifiers in python are nothing but user defined names to represent variables, functions, classes, etc. But there are few rules that we have to follow while defining an identifier:
  • You can define the variable using letters (a to z), numbers (0 to 9) or an underscore (_).
  • You cannot use digits to begin an identifier.
  • You cannot use reserve words to declare an identifier.
  • Other than underscore (_) you cannot use any other special characters, like !, @, #, $, etc. in an identifier.
E.g. of valid identifiers – Roll_no, admin_9, _newvariable, _nv1, _1stud, x123, x, y, z, salary, rollno, etc.
E.g. of invalid identifiers –
  • 1student – Starting with digits.
  • n%4 – Contains special character(%).
  • First name – Contains special character (space).
  • None – It is a reserved word.

Literals

Literals can be defined as data that is assigned to a variable or constant. Python supports following literals:
  • String Literals
  • Numeric Literals
  • Boolean Literals
  • Special Literals

String Literals

String literals are those texts that you specify under single or double quotation. There are two types of string literals: 
Single Line String Literals – The strings that are terminated within a single line called single line string literals. Eg.


>>>msg = “Hello, how are you?”
>>>print(msg)
Hello, how are you?

Multiline String Literals – A piece of text that is spread along multiline is called as multiline string literals. The multiline string literals can be separated by backslash symbol ( \ ) or by enclosing the text under triple quotation (“”” “”””). You can see the below example:
Example 1:
Example 2:

Numeric Literals

When we assign a value to a variable then that literals are called numeric literals. There are four different numerical types:
  • Int (signed integers): Numbers can be both positive and negative with no fractional part. E.g. 145, 90, 1546, etc.
  • Long (long integer): Integers of unlimited size followed by lowercase or uppercase L. E.g. 8706537623L, 6537153157263l, etc.
  • Float (floating point): Real numbers with both integer and fractional part. E.g. -26.6, 3.14, 10e5 (exponential form), etc.
  • Complex (complex): Numbers can be in the form of a+bj where ‘a’ is the real number and ‘bj’ is an imaginary number. E.g. 2 + 17j

Boolean Literals

A Boolean literal have only two values either true or false.

Special Literals

Python contains one special literal i.e. None. None is same as null in other language. We use None to assign null or empty value in some variable. E.g. message=None

Punctuators

These are symbols that are used in programming languages to organize sentence structures. Most common punctuators of Python programming language are:

‘ “ # \ ( ) { } [ ] , : .
Podcast Link: Click Here
YouTube Video Link: Click Here

Comments

Popular posts from this blog

Q & A Chapter 1 | Internet Basics | Class 10 CBSE | Computer Application

 Q & A of Chapter 1 Internet Basics A. Tick the correct options – 1. (b) TCP/IP 2. (a) Internet Service Provider 3. (a) URL 4. (b) HTTP 5. (a) Bridge 6. (a) home page 7. (d) All of these 8. (b) Domain Naming System 9. (b) Rules 10. (d) ARPANET B. Very Short Answer Type Questions – 1. In the URL http://www.myfirm.co.in/about.html , what do the following components depict? (a) http                                                 (b) in (a) Http represents a type of server and the protocol on the Internet (b) ‘in’ represents the domain extension of the website. 2. In the URL http://www.favmusic.com/contactus.html what does www.favmusic stand for? www.favmusic represents the domain name i.e. favmusic in www. 3. What does FTP stands for? FTP stands for File Transfer Protocol. 4. Differentiate between webpage and home page. A webpage refers to an electronic page usually written in HTML. It may contain text, images, graphics or hyperlinks. Th

Q & A Chapter 2 | Internet Services | Class 10 CBSE | Computer Application

 Q & A of Chapter 2 A. Tick the correct option – 1. (b) Browser 2. (a) surfing 3. (a) downloading 4. (d) FTP 5. (b) e-mail 6. (c) chat 7. (a) @ 8. (c) Acronyms 9. (d) Emoticons 10. (a) newsgroup B. Very short answer questions – 1. Name a few search engines. Which is the most popular one? Some common search engines are Bing, Google, Ask, Yahoo and MSN. The most popular search engine is Google. 2. What is an Acronym of FTP? File Transfer Protocol. 3. What is a newsreader? Give an example. A newsreader is a software tool or utility used to browse through newsgroup postings. A very popular newsreader in use today is Microsoft Outlook Express. 4. Name three sites that support e-mail services. Gmail, Outlook and Yahoo are three sites that support e-mail services. 5. What is the difference between attachments and FTP? Attachments are the files which are send through an e-mail for communication, while in FTP transfer of files takes place between FTP server and FTP clients and no communicat

Bit by Bit | Chapter 6 - Graphics and Sound in QB64 | QBasic | Class 7 CBSE | Computer Application

Bit by Bit | Chapter 6 - Graphics and Sound in QB64 A. Tick the correct option. 1. (d) screen mode 0 2. (b) 640 x 350 3. (d) White 4. (a) Lower-Right 5. (c) PSET 6. (c) Generate a tone for a short duration B. Fill in the blanks. 1. CIRCLE 2. PAINT 3. PLAY 4. Graphic 5. Pixels 6. Box C. True or False. 1. True 2. False 3. False 4. True 5. True 6. True D. Answer the following questions. 1. What is the use of SCREEN statement? The SCREEN statement is used to set the screen mode for displaying graphics. There are many screen modes and each screen modes have their own number which is from SCREEN 1 to SCREEN 13. The various screen modes differ in resolution. 2. What is a pixel? How is it related to resolution? The graphics which is displaying on the computer screen is made up of thousands of dots called pixel. Pixel stands for picture element. The number of pixels in an image determines the resolution of the image. Higher the resolution, cleaner the image will appear. 3. What is the differenc