Python Keywords, Identifiers ,Variables, Comment

In this Python Tutorial Only for beginners. You can easy to understand. 


Agenda

Python

  • Keywords
  • Identifiers
  • Variables
  • Comment

Keywords in Python

Keywords are the reserved words in Python.


In python, Keywords can not use as a variable name, function name or any other identifier.

 

Keywords are used to define the syntax and structure of the Python language.

 

There are 33 keywords in Python 3.7. Version

 

Python keywords has given below.

 


Python Identifiers

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

 

Rules

Identifiers is combination of letters in lowercase (a to z) or uppercase (A to Z) or digits (0 to 9) or an underscore _.

 

Example: hrs, var_1

 

An identifier cannot start with a digit.

 

1python is invalid, but python1 is a valid name.

Keywords cannot be used as identifiers.

for = 1

Output

  File "<interactive input>", line 1

    for = 1

           ^

SyntaxError: invalid syntax

We cannot use special symbols like !, @, #, $, % etc. in our identifier.

a# = 0

 

Output

  File "<interactive input>", line 1

    a# = 0

     ^

SyntaxError: invalid syntax

 

Variables

Variables are containers for storing data values.

Python has no command for declaring a variable.

Rules for Python variables:

A variable name must start with a letter or the underscore character(_)

A variable name cannot start with a number (0-9) and special characters like #, @

Variable names are case-sensitive (age, Age and AGE are three different variables)

Example:

hrs_1, HRS, python, pyThon  #valid

1hrs, @a,    #invalid



Comments

In Python programming, we use # hash symbol for comments.

Example:

#print hello

Print(“hello”)

Output

hello

If you want multi comment, you can also use # symbol.

#print python

#a=1

#print a

Print(“python”)

a=1

print(a)

Output

1

Triple Quotes “”” or ’’’

Generally triple quotes are used in python for multi string line. But you can also as multi comment. Example has given below:

“”” triple quotes are used in python

       for

       multi string line”””

Upcoming topics post has more programs and less theoretical definition because Program gives ideas to make own program and how to solve a problem? This is a way to improve your Programming Skill level.

Support us

Please support HRS INTERESTING FACTS Site. Share this Python Tutorial/Series to your friends.


@hrsinterestingfacts.blogspot.com # hrsinterestingfacts Python Tutorial/Series.

Thank You Everyone.


Previous Topics

Upcoming topics: Data types