Β 18 Jul 2020Β Β Β 4 min read
Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Pythonβs elegant syntax and dynamic typing, together with its interpreted nature,make it an ideal language for scripting and rapid application development in many areas on most platforms.
In this program we are using python3 . You can get it here. After installation you directly get stared with python IDLE. Or else you can use your favourite text editor and add python extension. In python IDLE you can get the output, directly as you have written the code and pressed entered.
In this program we are just printing out hello world string. If you are familiar with another programming language, then you can notice there is no main method here. Actually we don't have to explicitly call in the main method here. Python compiler will do this for us, That is one of the best part of python it is very easy get familiar with syntax.
First program:
copy code from here:
print("Hello world, this is my first line code ever!")
Variables in python Variables are basically like empty containers where you can store values. Unlike many conventional languages it doesn't have command for declaring Variables.
num1 = 234
num2 = 2434.46
name1 = 'John Snow'
a= b=c=d=1
print(c)
a,b,c,d = 12,44,546, "Var 4"
print(d)
Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data.
Data types in python:
β’ 1. Numbers
β’ 2. Strings
β’ 3. List
β’ 4. Tuple
β’ 5. Dictionary
# 1. Numbers
number1 = 3423
# 2. Strings
str1 = "This is the Testing string"
print(str1) β β β # Prints complete string
# 3. List
list = ['normal 1', 7834, " snow", 45641.54, 'john', 70.2 ]
print(list) β β β β # Prints complete list
print(list[0]) β β β # Prints first element of the list
# 4. Tuple
tuple1 = (342,35.54564,"new1",211,"FIle34",'Rock',2352)
print(tuple1) β β β β # Prints complete tuple
print(tuple1[4]) β β β # Prints fifth element of the tuple
# 5. Dictionary
dict1 ={'student 1':123,'Lecture 34':411,'Food':'Category'}
print(dict1) β β β βββββ #Printing whole dictionary
print(dict1['student 1']) β β# Prints value for 'Student 1' key
An else statement can be combined with an if statement. An else statement contains the block of code that executes if the conditional expression in the if statement resolves to 0 or a FALSE value. The else statement is an optional statement and there could be at most only one else statement following if.
n1 = 122
n2 = 223
if(n1 !=n2):
ββprint ("n1 is not equal to n2")
if n1>n2:
ββprint ("n1 is greater than n2")
elif n1==n2:
ββ print ("n1 is equal to n2")
else:
ββ print ("n1 is lesser than n2")
A function is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reusing. Functions help break our program into smaller and modular chunks. As our program grows larger and larger, functions make it more organized and manageable.make it an ideal language for scripting and rapid application development in many areas on most platforms. Furthermore, it avoids repetition and makes the code reusable.
num1 = int(input("Enter number: "))
def EvenOdd(num1):
ββif num1%2==0:
ββββprint("Entered number is Even ")
ββelse:
ββββprint("Entered number is Odd ")
EvenOdd(num1)
References π
Taken from TutorialsPoint and porgrammiz. You can connect me via below links