DEV Community

Cover image for Python Foundation with Data Structures & Algorithms - Part 01
NirmaniWarakaulla
NirmaniWarakaulla

Posted on • Edited on

Python Foundation with Data Structures & Algorithms - Part 01

Introduction to Python Programming Language

What is Python?

Python is a popular programming language. It was created by Guido van Rossum, and released in 1991.

It is used for:

artificial intelligence
big data
web development (server-side)
software development
mathematics
system scripting

First Python Program

 print("www.machinelearning.org.in")
Enter fullscreen mode Exit fullscreen mode

www.machinelearning.org.in

 print("Python")
 print("Data Science")
 print("Machine Learning")
Enter fullscreen mode Exit fullscreen mode

Python
Data Science
Machine Learning

Single Line Comment

Comments start with a #, and Python will render the rest of the line as a comment:

 'print("Hello")  #This is a comment'
Enter fullscreen mode Exit fullscreen mode

Hello

 'print("Python")
 print("Data Science")
 #print("Machine Learning")
 print("Deep Learnig")
 print("Artificial Intelligence")'
Enter fullscreen mode Exit fullscreen mode

Python
Data Science
Deep Learnig
Artificial Intelligence

Multiline Comment

Python will ignore string literals that are not assigned to a variable, you can add a multiline string (triple quotes) in your code, and place your comment inside it:

 '''
 print("Python")
 print("Data Science")
 print("Machine Learning")
 print("Deep Learning")
 '''
 print("Artificial Intelligence")
Enter fullscreen mode Exit fullscreen mode

Artificial Intelligence

Assign Value to a variable
 a=10
 b=3.134
 c="Machine Learning"
 print(a)
 print(b)
 print(c)
Enter fullscreen mode Exit fullscreen mode

10
3.134
Machine Learning

 print("Value of a :",a)
 print("Value of b :",b)
 print("Value of c :",c)
Enter fullscreen mode Exit fullscreen mode

Value of a : 10
Value of b : 3.134
Value of c : Machine Learning

 print(a,b,c)
Enter fullscreen mode Exit fullscreen mode

3.134 Machine Learning

 print("Value of a :",a,"Value of b :",b,"Value of c :",c)
Enter fullscreen mode Exit fullscreen mode

Value of a : 10 Value of b : 3.134 Value of c : Machine
Learning

 print("Value of a :",a,"\nValue of b :",b,"\nValue of c 
:",c)
Enter fullscreen mode Exit fullscreen mode

Value of a : 10
Value of b : 3.134
Value of c : Machine Learning

 print("Value of a :",a,end='\n')
 ("Value of b :",b,end='\n')
 print("Value of c :",c,end='\n')
Enter fullscreen mode Exit fullscreen mode

Value of a : 10
Value of b : 3.134
Value of c : Machine Learning

 print("Value of a :",a,end=' ')
 print("Value of b :",b,end=' ')
 print("Value of c :",c,end=' ')
Enter fullscreen mode Exit fullscreen mode

Value of a : 10 Value of b : 3.134 Value of c : Machine
Learning

Accepting User Inputs

input( ) accepts input and stores it as a string. Hence, if the user inputs a integer, the code should convert the string to an integer and then proceed.

 a=input("Enter any value:")
 print(a)
Enter fullscreen mode Exit fullscreen mode

Enter any value:Machine Learning
Machine Learning

 print(type(a))
Enter fullscreen mode Exit fullscreen mode

< class 'str' >

Note that type( ) returns the format or the type of a variable or a number

Top comments (0)