Categories
Programming Hues Python Dairies

How To Learn Python In A Better way

Python being a popular shot now-a-days and is easy in context with the syntax of it. It is one of the best paid programming languages in today’s era. Python is one of my favourite languages and I am sure, you will enjoy learning python to a great extent.

However, learning new language and getting through new concepts of that language is not easy. I know that everyone assumes this syntax eating as an overwhelming procedure. But first of all, Congratulations !! 😀 for choosing Python as your new target. Python will definitely help you in tweeking Technology and creating Magic 😛 So lets jump in !!

What is Python ?

Python is an interpreted, interactive, object – oriented high level language. It was developed by Guido van Rossum and was named after a British comedy group Monty Python. Python’s presence in the world is everywhere, Python is used in building and maintaining some really popular sites and apps like Instagram, Dropbox, Quora, and Youtube.

To know more about what exactly you can do with Python switch to the “Why is Python worth learning this Year”. You will find great applications of python there.

Install Python and Get ready !!

Python is free and open – source software, that works on various platforms including Mac, Linux and Windows. It comes installed in Mac and Linux. Also, in HP laptops we have python installed with Windows.

You can install the latest version of python from here. For detailed installation procedure, you can click here.

After installing Python, you will have an interactive shell and an IDLE (named after Monty Python’s Eric Idle) to code in python. The shell is less powerful then IDLE, but is useful to try one-line code statements. IDLE can do the work of shell, but also allows you to write multiple lines of code, that can be saved as a script and executed later. It allows code reusability.

I have a Plan to code !!

In my thought, learning python is similar to riding a Bike, you will have to accelerate but will enjoy the journey there after. To code a problem, you will be in need of a Plan, by plan I mean, you will have to build the logic and then through syntax you can make it working. Thus, work hard on your logic building and that will give you the ability to figure out the plan to solve a given problem. So, lets learn to have a plan !!

without a plan on how to solve problem, you will be like Elmo !! 😀

Lets get started with Python !!😀

The Basics :

  • Variables – Variable is just a value stored in a memory cell which is named by a word. The value can be an integer, boolean (True / False), strings, float, and so many other data types. This can be seen by a simple example.
one=1
bool_val=True

here one is the word (it is a name given to a memory cell) and 1 is an integer and bool_val is a boolean variable storing True.

  • Conditional Statements – “if”, “elif”, “else” are conditional statements.
    • The if statement uses an expression to evaluate whether the given statement is True or False, then it executes the code which is indented inside the ‘if’ block, if the statement evaluates to True.
    • The elif statement is used for checking upon further statements, If the statement in ‘if’ evaluates to False, then ‘elif’ condition is checked, If it evaluates to true the code in ‘elif’ block gets executed.
    • The else statement is used when all the conditions of ‘if’ and ‘elif’ evaluates to False. The code in ‘else’ block gets executed whenever the conditions in ‘if’ and ‘elif’ statements becomes False.
    • The simple examples of Control Flow Statements are :
if True :
    print("I am in if block.")        

Code in the ‘if’ block executes as the condition is true.

if 6>7 :
    print("The if block.")            
elif 7>6 :
    print("The elif block.")          

The ‘if’ statement evaluates to False, then ‘elif’ statement is checked which evaluates to True, hence the code block indented after ‘elif’ statement gets executed.

if 6>7 :
    print("The if block.")            
elif 5>7 :
    print("The elif block.")          
else :
    print("The else block.")          

The ‘if’ and ‘elif’ statement evaluates to False, then ‘else’ statement is checked which evaluates to True, hence the code block indented after ‘else’ statement gets executed.

  • Loops / Iterator – In python we iterate by : “for” and “while”.
    • while looping : the while loop means while the condition is true, the code inside the block is executed. So the example below prints numbers from 1 to 5.
    • for looping : the for loop uses an iterating variable and then for every iteration the for code block executes. The for block iterates the iterating variable. The below code will print numbers from 1 to 5.
num=1
while num <=5 :                             
    print(num)
    num=num+1

The indented code gets executed, until the while condition evaluates to True.

for i in range(1,6):                        
    print(i)

Here, in for loop we have ‘i’ as iterating variable, and range function is used to iterate it from 1 to 5.

Yeah!! Let’s Celebrate, we are done for today !!

We have learned a lot today, Go and throw a small party for yourself 😀 , In the next post, we will talk upon Python Data Structures. Till then have fun !!, shower your likes and comments upon this post. Also, give it a loud share 😀 .

Also, you can find “Dare to Learn” on Instagram and Facebook for more interesting stuff 😀 .

Rachna Agrawal's avatar

By Rachna Agrawal

I am a confident girl believing in Technology. Creating magic via my technical abilities to make world a better place is my motto of Life. I have learned C, Java and Python and made some Android Apps too, I am also a Machine Learning Enthusiast. I believe learning and growing is a gradual process, so let's dare to Learn and Grow together.

2 replies on “How To Learn Python In A Better way”

Leave a reply to 4 Undeniably Important Data Structures In Python – Dare to Learn !! Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started