Environment Setup Python | Python Tutorial | Learn Python
×

Environment Setup of Python

2893

Download python from www.python.org download section.
1. It is mandatory that the version should be 3.6
2. Then download the latest version of Python 3.6.5
3. Before install of python, do not forget to select the add python 3.6 to path otherwise it will create errors afterword.
4. Install it
5. Check it is properly installed or not you have to write cmd on start.
6. Python will display for use.


IDE
When you download python, you will get IDLE along it, in which you can do python coding. There are many options available for python coding such as PyCharm, Jupytr.

For example:


Syntax in python
The first program in python

You can execute python program by more than 1 method that can be through command prompt, notepad method

Command prompt
1. From Start open cmd
2. Press DIR
3. Check the program file 1.py exists there.
4. Type 1.py i.e. the name of the program and .py is the python extension
5. The output will disply i.e. hello


By another method I.E Interactive mode
We can invoke the interpreter without passing any script file as parameter display the following prompt -


Type statement print("coding tag")
The output will be



Indentation in Python
One of the most impressive features in python is an indentation that is used to indicate a block of code. In C, C++, Java, there are braces used for the scope of code but python language is free from braces. In this, the use of braces are reduced which in turn make the code very simple to write and understand.
Below is the statement used for the indentation in python language

e.g.

if 6>3:
        print("six is greater than three!")

Output:

six is greater than three!

Python will create an error with the absence of indentation

e.g.

if 6>3:
        print("six is greater than three!")

Output:

Traceback (most recent call last): File "python", line 2 print("six is greater than three!") ^ IndentationError: expected an indented block



Comments in Python
For the objective of in-code documentation, python language has commenting capability.
We can start a comment with the use of # at the start of the line which will render by a python as a comment line and triple quotes can be used for multi-line comments i.e.

Example
Single line comment

#this is a comment in python programming.
print("welcome coding world!")

Multiline comment
""" this is a multiline comment """


Input and Output in Python
In python programming, we can take input from the user with the help of input() function that is explained below with the help of an example:

# Python program to illustrate
# getting input from the user
name = input("Enter your website name: ")

# user entered the name 'codingtag'
print("welcome in", name)

Output
Enter your website name: welcome in codingtag
A simple program in python for getting input i.e. integer from the user and addition of the numbers.


# Python3 program to get input from the user
# accepting integer from the user

number1 = int(input("Enter number1: "))
number2 = int(input("Enter number2: "))

number3 = number1 + number2
print("Product is: ", number3)

Output
Enter number1: Enter number2: ('Product is: ', 9)


Reserved words in python programming language
Similar to other languages such as Java, c, and c++, python also contains some reserved words. Reserved words are also known as keywords that are defined with predefined syntaxes and meaning in the specific language. These keywords further have to be used to develop python programming instructions. They never be used as an identifier. Python 3 contains 33 keywords whereas python 2 contain 3 keywords less than python 3 i.e. 30. The following command can be used to check the list of keywords.
>>> import keyword
>>> keyword.kwlist

Output
In output list of keywords will display on the screen which was shown below in the screenshot.


Identifiers in python
The identifier is known as the name that is given during programming for the entities such as functions, class, variables etc. to make one entity distinguishable to another entity. There are some rules defined in python language while writing any identifiers that are written below in points:

* An identifier never initiate with a digit.1variable
* All other identifiers start with lowercase letter except Class names that will start with uppercase letter
* Identifiers can be a combination of lowercase and uppercase letters or digits for e.g. var_2
* The keyword can never be used as an identifier.
* Never use special symbols as an identifier such as #, $, %,@,etc
* They can be of any length
* For private identifier, start an identifier with a single leading underscore and two leading underscores can be used for stronger identifier privacy.
* The identifier is a language-defined special name if it terminates with two trailing underscores.



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments