Skip to main content

Identifiers,Variables and Keywords

Identifiers

An identifier is a name given to entities like variables,functions,class, functions etc. It helps to differentiate one entity from another.

Rules for writing identifiers

1.Identifiers can be a combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore _. 
Names like myClass, var_1 and print_this_to_screen, all are valid example.

2.An identifier cannot start with a digit. 1variable is invalid, but variable1 is a valid name.

3.Keywords cannot be used as identifiers.
Eg: global = 1 is invalid

4.We cannot use special symbols like !, @, #, $, % etc. in our identifier.
a@=0 is invalid

5.An identifier can be of any length.

Things to Remember
  • Python is a case-sensitive language. This means, Variable and variable are not the same.
  • Always give the identifiers a name that makes sense. While c = 10 is a valid name, writing count=10 would make more sense, and it would be easier to figure out what it represents when you look at your code after a long gap.
  • Multiple words can be separated using an underscore, like this_is_a_long_variable.

Variables

A variable can be used to store a certain value or object. In Python, all numbers (and everything else, including functions) are objects. A variable is created through assignment. Their type is assigned dynamically.
Eg:
x='binu'
y=23
z=24.5
l=399379379379387983793773973977000102
use type(object) to know the type of the variable object
Eg: type(x)      type(y)            type(z)                    type(l)
<type 'str'>     <type 'int'>   <type 'float'>           <type 'long'>
use dir(object) to know the functions associated with the object
When we create a program, we often like to store values so that it can be used later. We use objects to capture data, which then can be manipulated by computer to provide information. By now we know that object/ variable is a name which refers to a value. It has a type and also store some value.

Variable can be mutable or immutable. A mutable variable is one whose value may change in place, whereas in an immutable variable change of value will not happen in place.

Things to Remember:
  • Variables are created when they are first assigned a value.
  • Variables type is determined by the value which is assigned.
  • Variables must be assigned a value before using them in expression,
  • Variables refer to an object and are never declared ahead of time.

Keywords

Keywords are the reserved words in Python.

We cannot use a keyword as a variable name, function name or any other identifier. They are used to define the syntax and structure of the Python language.

In Python, keywords are case sensitive.

There are 33 keywords in Python 3.7. This number can vary slightly over the course of time.

All the keywords except True, False and None are in lowercase and they must be written as they are. The list of all the keywords is given below.
Falseawaitelseimportpass
Nonebreakexceptinraise
Trueclassfinallyisreturn
andcontinueforlambdatry
asdeffromnonlocalwhile
assertdelglobalnotwith
asyncelififoryield

Comments

  1. Thanks for sharing such informative blog.
    Become a Data Science expert with us. study Data Science Course in Hyderabad with Innomatics where you get a great experience and better knowledge.

    ReplyDelete
  2. http://wisdommaterials.com/
    https://www.globalcompaniesinfo.com/
    http://wisdomallcodes.com

    ReplyDelete

Post a Comment

Popular posts from this blog

Classes and Objects in Python

Python is an object-oriented programming language, which means that it provides features that support object-oriented programming. The basic components of object oriented programming are classes and objects. A Class is a blue print to create an object. It provides the definition of basic attributes and functions of objects. Object is a running instance of the class having the identity(name), properties( values) and behaviors(functions). The Object oriented program thus consist of object definitions (classes) and most of the computations and functions are mentioned as operations on the object. Each object definition corresponds to some object or concept in the real world, and the functions that operate on these object correspond to the ways real-world objects interact. We have learned objects of string, list, tuple etc…and used the properties and functionalities of these objects which are built into the Python. Now we are going to create our own(user defined) objects. Th

Files in Python , Exception handling

While a program is running, its data is in main memory. When the program ends, or the computer shuts down, data in memory disappears. To store data permanently, you have to put it in a file. Files are usually stored on a secondary storage device(hard disk, pen drive, DVD,CD etc).  When there are a large number of files, they are often organized into directories (also called “folders”). Each file is identified by a unique name, or a combination of a file name and a directory name.  By reading and writing files, programs can exchange information with each other and generate printable formats like PDF. Working with files is a lot like working with books. To use a book, you have to open it. When you’re done, you have to close it. While the book is open, you can either write in it or read from it. In either case, you know where you are in the book. Most of the time, you read the whole book in its natural order, but you can also skip around. All of this applies to files as well.