bing
Flat 10% & upto 50% off + Free additional Courses. Hurry up!

Tokens and Variables

 

Tokens are the smallest unit of program. There are following tokens in Python:

  • Reserved words
  • Identifiers
  • Literals
  • Operators

 

Reserved Words 

Reserved Words are also known as keywords which express a special meaning to the compiler and interpreter. Keywords in python are –

return or None and not
asset def class continue break
from finally elif del except
global for if else import
raise try True False pass
nonlocal in as is lambda

 

Identifiers

An identifier is a sequence of numbers and characters. These are the names given to the basic building blocks in a program. These can be class, variables, functions, object, lists, dictionaries etc.

Rules for defining identifiers are –

  • First character of an identifier can be character, underscore ( _ ) but not digit.
  • No special character except underscore ( _ ) can be used as an identifier.
  • Reserve words cannot be used as an identifier name.
  • Python is a case sensitive language so ‘a’ and ‘A’ are different identifiers.

 

Literals

Literals can be defined as a data that is given in a variable or constant. Python have following literals:-

  • String Literals
  • Numeric Literals
  • Floating Literals
  • Boolean Literals
  • Collection literals

 

Variables

A variable is a memory address that can change and when memory address cannot change then it is known as constant. Variable is a name of the memory location where data is stored. Once a variable is stored then space is allocated in memory. It defines a variable using a combination of numbers, letters and the underscore character.

There are a few rules: a variable must begin with a letter or an underscore, and the variable name is case sensitive.

 

Assigning Values to Variables

There is no need for explicit declaration to reserve memory. The assignment is done using the equal (=) operator. Some example of legal python variables are –

i = 1

i_j = 2

Example 

>>> a = 1

print a

Output

1

 

Multiple Assignment:

You can assign a single value to the multiple variables as follows –

a = b = c = 20

Where a, b, c are the variable.

Also you can assign multiple values to the multiple variables as follows –

a = b = c = 20, 25, 30

print a

print b

print c

Output

20

25

30

Learn more about PYTHON TOOLKIT in this insightful blog now!

"0 Responses on Tokens and Variables"

Training in Cities

Bangalore, Hyderabad, Chennai, Delhi, Kolkata, UK, London, Chicago, San Francisco, Dallas, Washington, New York, Orlando, Boston

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.

top

Sales Offer

  • To avail this offer, enroll before 05th December 2016.
  • This offer cannot be combined with any other offer.
  • This offer is valid on selected courses only.
  • Please use coupon codes mentioned below to avail the offer
offer-june

Sign Up or Login to view the Free Tokens and Variables.