Start with Interactive Mode
friends we are here to learn the python 3 it is somewhat different from python 2 lets begin. If the commands are read from a tty the interpreter is said to be in interactive
mode .Interactive mode is a command line shell which gives immidiate feedback for each statement and while running previously fed statements in active memory The interpreter
prints a welcome message stating its version number and a copyright notice
before printing the first prompt:
$ python3.6
Python 3.6 (default, Sep 16 2015, 09:25:04)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Python 3.6 (default, Sep 16 2015, 09:25:04)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
now type the following code
>>> print ("HELLO, WORLD!")
This produces the result as
HELLO, WORLD!
Scripting Mode
On Installing python you will get a default python IDE "IDLE" lets write some code now in the Invoking the interpreter with a script parameter begins execution of the script and continues until the script is finished. When the script is finished, the interpreter is no longer active.
Let us write a simple Python program in a script. Python files have extension .py. Type the following source code in a nads.py file
print("HELLO, WORLD!")
you should have Python interpreter set in PATH variable.to know about how to set python interpreter view my previous posts Now, try to run this program as follows
$ python nads.py
This produces the following result
HELLO, WORLD!
Python Identifiers
Python identifier is a name used to identify a variable, function, class, module or other object(all of this will be explained in the coming lessons).many other programming languages insist on having every identifier used in code have type information declared for it.but python doesn't need so. An identifier starts with a letter A to Z or a to z or an underscore (_)
followed by zero or more letters, underscores and digits (0 to 9).
Python does not allow punctuation characters such as @, $, and % within identifiers. Python is a case sensitive programming language. Thus, Atom and atom are two different identifiers in Python.
The naming conventions for python are
Python does not allow punctuation characters such as @, $, and % within identifiers. Python is a case sensitive programming language. Thus, Atom and atom are two different identifiers in Python.
The naming conventions for python are
- Class names start with an uppercase letter. All other identifiers start with a lowercase letter.
- Starting an identifier with a single leading underscore indicates that the identifier is private.
- Starting an identifier with two leading underscores indicates a strongly private identifier.
- If the identifier also ends with two trailing underscores, the identifier is a language-defined special name.
here is an example of python identifiers:
name_value = "this is a string value "
num_value = 458
num_value = 458
RESERVED WORDS
reserved words are keywords those words which can't be used 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.
and | exec | not |
---|---|---|
assert | finally | or |
break | for | pass |
class | from | |
continue | global | raise |
def | if | return |
del | import | try |
elif | in | while |
else | is | with |
except | lambda | yield |
LINES AND INDENTATION
A python programme is composed of a sequence of logical lines each made up of one or more physical lines of codes in python end of a physical line marks the end of the statement in other languages like java there is semicolon added at last to end of the statement
In python there is no curly brackets {} like in other languages to indicate blocks of code for class and functions definition or flow control . Here in python they uses indentation to indicate the block of code the number of spaces is variable but the different statements within the code blocks must be at same amount of space like in the code given below
if True:
print("true")
else :
print("false")
print("true")
else :
print("false")
that's all for this post guys More on this part will be discussed in the next post
No comments:
Post a Comment