Home Education Learn Python Programming (Most powerful Language)

Learn Python Programming (Most powerful Language)

0

Python is a scripting language that is a powerful dynamically typed language, supports numerous high-level constructs and data structures. Also, learning the basics and writing programs in Python programming is very easy for beginners.

Index

  1. What is Python?
  2. Applications of Python Programming.
  3. Installing Python Programming Language on your device.
  4. Python
  5. Loops
  6. Comparison of Java and Python
  7. Operator Precedence
  8. Conclusion
  9. QnA

What is Python?

What is a Scripting language?

Scripting languages are that programming language that doesn’t need a compiler, instead of the programs directly interpreted.

Do check Our Programming Language Page.

Applications of Python Programming

Python can be used in various applications right from eCommerce website development to email search applications, fraud mail detection, face recognition, and so on.

Python is useful in many computing environments including the following:

  1. The command line in a monitor or terminal window.
  2. Graphical User Interface, including the web.
  3. Mobile devices.
  4. Embedded Systems.
  5. The cloud.
  6. Backend servers.

Installing Python on your device

Go to https://www.python.org/downloads/ to download Python software.

Install the downloaded software.

On your desktop, a console icon is created with the name “python”.

Just run it and start typing your code.

What should you know before moving to Python Programming from any other language?

  1. You don’t need to declare a variable.
  2. No need to use data types.
  3. Neither semicolons

You don’t have to terminate a line, just start with a new line

  1. To use nesting in if…else you have to use the elif keyword.
  2. No use of increment( var++ ) or decrement( var– ) keyword.

To increment/decrement, we have to use the standard logic i.e.

var= var+1 or var= var-1
  1. No need to declare include statements nor the import functions.
  2. No need to use classes, objects, when there’s no need.
  3. It is a bit slower for execution.
  4. But very powerful.

Python Programming in Details

Python Keywords

falseclassfinallyisreturn
nonecontinueforlambdatry
truedeffromnonlocalwhile
anddefglobalnotwith
aselififoryield
assertelseimportpass
breakexceptinraise

Comments

If we want to give some information in the code, then we can use the hash character( # ) at the starting of the line.

This ( # ) is a single line comment.

Ex.
#HEY ………

You can also use the multiline comment. Instead of using the hash comment for each line, we can use the triple-double quotes( “”” ).

Ex.

“”” Hey

How are 

You??

“””

The comments are ignored.

Writing Your first code in Python Programming Language

Let’s print Hello World.


print(“ Hello World” )

That’s it.

Python doesn’t have Semicolons.

You don’t need to add headers, functions, variables, to print a single word. Just type print and your message.

I told you above, it’s the easiest Programming language.

If you are a beginner then you will not have any problem understanding the programs but if you moved from other programming languages, the logics are simple but some keywords, functions may confuse you because they have a bit different syntax and also you may feel a little hard to resist.

Variables

In python, you don’t have to worry about data types because Python will do it for you automatically.

Ex.

a = 10

b = “Hello”

c = “Hey Google.” 

You just have to focus on your logic and program because the syntax is very simple.

Let’s go for the loops.

Loops in Python Programming

Note: Python doesn’t accept braces, So for loops, we are going to use space or tab space.

Let’s suppose, I need to write an if/for multiline statement then after the expression I am going to use a tab space that denotes that the statements which have tab space are going to execute under if/for.

It will look like this.

if /for expression:
——–
——–
if/for expression:
——–
——–
statements
————




After hitting the continue keyword, the first statement will continue for execution.
  1. If … else

It is the decision-making loop. There are 3 keywords.

if, else, elif( shorter version of else if )

Syntax:

if expression:

    statements

elif expression:

    statements

else: 

    Statements

We don’t use brackets anymore, instead, we use a colon( : ).

Ex. 

if n=0:

print(“The number is 0”)

elif n<0:

print(“The number is negative”);

else:

printf(“The number is positive”);

  1. While loop

As I said above, python doesn’t accept braces, instead, we use a colon( : ).

Syntax:

while expression:

Statements

Ex.

While n>=0:

n=n-1

print(n);

Continue and Break

The continue is a keyword that is used in loops. Whenever the continue keyword is called, it requests the interpreter to skip the below statements and go for the first line of the loop.

if /for expression:
——–
——–
if/for expression:
continue
——–
——–                   
statements
————







After hitting the continue keyword, the first statement will continue for execution.

Ex.

Run this code and see what the result is.

while n > 0:              

 n = n -1

   if n == 10:

      continue

   print ‘Current value :’, n

But in the Break keyword, when it’s called, it terminates the loop.

Ex.

if /for expression:
——–
——–
if/for expression:
continue
———
———
statements
——-
——-







As you can see, if the break keyword got hit, then it will skip the other statements and force the loop to get terminated.

Ex.

while n > 0:              
  print 'Current value :', n
   n = n -1
  if n == 5:
       break

Comparison of Java and Python

JavaPython
Java programs are compiled and then interpreted into Byte code.Python programs are interpreted directly like Script languages. 
Use a semicolon(;) for line termination.No use of the semicolon.
Uses curly braces to denote the start and the end.Use space and tab spaces.
Needs to declare the variable first.It can be declared a variable at the time of initialization.
Needs to declare a variable with data types.No need to use the data types.
Faster execution than Python.Slower execution.
Needs to write longer lines of code compared to Python.5 times less code.
The use of the class is compulsory.No need to use class until it’s needed.
Hard to understand, for other people.Easy to understand.

Operator Precedence

OperatorDescription
+Addition & Multiplication
/ * % //Division, Multiplication, Modulo, Floor Division
**Exponentiation(raise to the power)
~ + –Complement, (+ and – used for the method names ex. +@ and -@)
>> <<Right & Left Bitwise Shift
&Bitwise ‘AND’
^ |Bitwise exclusive ‘OR’ and regular ‘OR’
<= < > >=Comparison Operator
<> == !=Equality Operators 
= %= /= //= -= += *= **=Assignment Operators
is is notIdentity Operators
in not inMembership Operators
not or andLogical Operators

Input in Python

To get input, Python has an in-built function i.e. input(). 

Input() functions read input from the console.  Read input is always in string format.

Syntax:

input(prompt)

Where the prompt keyword is for a message.

Ex.

//Getting name as input and greeting him/her.
myName= input(“ Enter your name”)
myName
print(‘ Hey! How are you ‘, myName)

Let’s understand

As for the first line, we assign input for the variable myName and print the input prompt message.

The next line variables state that, if the user entered any name then it will store in myName variable.

On the last line, we displayed Hey! How are you with the name that the user entered.

Conclusion

Python is overtaking the C language. Python has been around since 1991 and is considerably and consistently in the top 10 most popular computing languages. Organizations like Google, YouTube, Dropbox, Netflix, and Hulu spend a huge amount on development in Python.

QnA

Q1. How to practice Python?

You have to understand and apply everywhere and solve problems.

Q2. Is python language free?

Yes.

Q3. Can I do Python programming in IPad or on mobiles?

Yes. But it’s going to take more effort because of the small keyboard.

Q4. Who created the Python Language?

Guido van Rossum

Q5. Where to practice Python?

You can download the Python software or you can run the applications online on the website onlinegdb.com

You completed the basics, now it’s time to go for examples. :- Python Examples and Functions-beginners

NO COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Exit mobile version