/Python-Basics

Programming Fundamentals of Python

python

Python Coding Basics

The purpose of this article is to demonstrate the basic coding in Python Programming Language. The code for the same is also provided in "code" folder.

Outcomes

The reader will get well acquainted with the basic coding syntax of Python Programming Language.

Example:

print("Basic Coding: Python Programming Language")

Output:

python

Table of Contents


What is Python?

python


Basic Codes:

1)print()

#using double quotes
print("In double quotes")

#using single quotes
print('In single quotes')

#printing a variable
a=10.5
print(a)

#printing with formatting
print("value of a is %f" %a)

print("value of a is {}" .format(a))

#printing multiple variables
x=10
y=20
print('x={0} y={1}'.format(x,y))
print('y={1} x={0}'.format(x,y))

Output:

python

2)Comments

# We use "#" for single line comment

'''
We can write multiline comment using three qoutes(')
The code within the comment must not be executed
print("For example, this line of code will not be executed")
'''

print("And this line of code will be executed")

Output:

python

3)Assignment Operator

# We use "=" for assignment of one value to the variable
a= 10
print("The value of a is "+str(a))
# NOTE: We have to convert int to string for maintaining same type in print statement


# We can also assign multiple variable at a time
b,c=20,30
print("The value of b & c is "+str(b)+"&"+str(c))

#We can also assign value of one variable to another variable
d=a
print("The value of d is "+str(d))

Output:

python

4)input()

#use input funtion to take the input from the user, pass the information you need as the parameter
x=input("What is your name? ")
print('My name is {0}'.format(x))

#if you want the input to be of string tupe then simply typecast it to integer using the int()
y=int(input("What is your age? "))
print('My age is {0}'.format(y))

Output:

python