<Prathamesh/>

Learn Python Basics

Β 18 Jul 2020Β  Β Β 4 min read


Introduction πŸ“’

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.


Hello world πŸ‘‹

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 πŸ“¦

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'

Multiple Assignment

a= b=c=d=1
print(c)

a,b,c,d = 12,44,546, "Var 4"
print(d)

Data types πŸ’Ύ

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


Similarities between Java

  • Tuple is similar to the list. but for its declaration we use parenthesis()
  • Tuples cannot be updated like list
  • Dictionary is Similar to hashtable.
  • Dictionaries are enclosed by curly braces { } and values can be assigned and accessed using square braces ([])
# 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

If else πŸ‘ / πŸ‘Ž

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")

Functions πŸ‚

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

All Blogs
      Created with ❀️ by  Prathamesh Mali © 2021
Built with Β gatsby-logo