Tech Blogs

Tech Blogs

A Gentle introduction to python

A Gentle introduction to python

Write your first Program in python

Python is a very simple language , and has very intuitive syntax.It encourages programmer write his code easily and efficiently(with less line you can do more) For Example: You can just write print("some line") to print it out to the screen and yes you can first prototype your logic first and easily and then later convert it into other language

In this article We'll see some basics of python to get started

Printing out a line

  1. As discussed above you have to write the following to print out a line
print("some string here")
print("My name is Pratyush")

2. Not only the strings but also you can add numbers to print and show it in the screen

print(2)
print(2.5)

variables and types

As we have taken first steps by printing the line to the screen,Now let's move forward to yet another important thing on any programming language i.e Variables and types Variables are like boxes with label as the variable name. You can store any thing in it. But in any programming language there is Number , strings(set of characters) and boolean(true or false type ) of variables

Numbers

Python gives two types of numbers-Integers(whole numbers like -1 ,-2,2,3) and floating point numbers(decimals).

To define an Integer use the following syntax

myfirstinteger = 7
print(myfirstinteger)

To define a floating point Number we can use one of the following syntax

myfirstfloat = 7.0
print(myfirstfloat)

or

myfirstfloat = float(7)
print(myfirstfloat)

Strings

Strings are nothing but a stream of characters.Strings are defined either with single quote or a double quotes

myfirststring = 'hello'
mysecondstring = "second"
print(mystring)
print(secondstring)

The difference between the two is that using double quotes makes it easy to include apostrophes and using the single quotes insides the double quotes it does not give any errors

mystring = "Don't worry about apostrophes"
print(mystring)

As we have discussed a lot let's take a time to test understandings.

Exercise

The aim of this exercise is to define three types of variables string , Number and float and save respective values to its respective variables or you can say containers.

  • The string should be named myfirststring and should contain the word Amazing.
  • The floating point number should be namesd asmyfirstfloat and should contain the number 10.0 . Try to do it both the ways we have discussed.
  • The Integer should be named myfirstinteger and should contain the number 10

Congratulations on your first line of code in python we will discuss more on python in next article till then keep practising and keep reading 🙂

 
Share this