Variable, Expression, Condition and Functions

Variable, Expression, Condition and Functions

Python (Variable, Condition, Expression and Functions)

variables in python, python global variable, pythonpath, python global, python declare variable


We all have already gone through from the Python Language Introductionwhere we have seen a lot of basic things from it.

Now lets begin with some concepts regarding Python to write some codes.

Running your First Code in Python :

Python programs are not compiled, rather they are interpreted. Now, let us move to writing a python code and running it.


Making a Python file :

Python files are stored with the extension “.py”. Open text editor and save a file with the name “hello.py”. Open it and write the following code:

print ("hello world")
# no semi-colon is to be used

output :

hello world 

If you are using linux OS then

Reading the file contents:

Linux System – Move to the directory from terminal where the created file (hello.py) is stored by using the ‘cd’ command, and then type the following in the terminal :

python hello.py

Windows system – Open command prompt and move to the directory where the file is stored by using the ‘cd’ command and then run the file by writing the file name as command.


Variables in Python :
Variables need not be declared first in python. They can be used directly. Variables in python are case sensitive as most of the other programming languages.You have to be careful with the upper and lower characters you are using for declaring the variables.

Example:

a = 4
A = 5
print a
print A

output :

4
5

Expressions in Python
Arithmetic operations in python can be performed by using arithmetic operators and some of the in-built functions.

a = 5
b = 6
c = a + b
print (c)
d = a * b
print (d)

output :

11
30


Conditions in Python :
Conditional output in python can be obtained by using if-else and elif (else if) statements.


a = 4
b = 8
if b % a == 0 :
    print ("b is divisible by a")
elif b + 1 == 10:
    print ("Increment in b produces 10")
else:
    print ("You are in else statement")


output :

b is divisible by a 


Functions in Python

A function in python is declared by the keyword ‘def’ before the name of the function. The return type of the function need not be specified explicitly in python. The function can be invoked by writing the function name followed by the parameter list in the brackets.


# Function for checking the divisibility
# Notice the indentation after function declaration
# and if and else statements
def checkDivisibility(a, b):
    if a % b == 0 :
        print ("a is divisible by b)
    else:
        print("a is not divisible by b")
#Driver program to test the above function
checkDivisibility(4, 2)

The output is :

a is divisible by b

So, python is a very simplified and less cumbersome language to code in. This easiness of python is itself promoting its wide use in the whole world.

Next Article : Maximum storing capacity of int in Python

Recommended Post : 








In this article i have explained a brief details of Variables related to Python.



 #tkinter
 #python training
 #python data analysis
 #best python tutorial
 #python classes near me
 #learn python for beginners
 #python online training
 #django course
 #advanced python course
 #python course fees
 #introduction to data science in python
 #free python tutorial
 #learn python basics
 #python study




















































Post a Comment

0 Comments