Some simple operations performed in python...

Hello, Welcome to the programming Section of NewAgeInformers!!!

              I am here with my new post about python language. Some topics we covered in our previous post. So now we will discuss some new topics. So here we go...

                                              PYTHON

For getting a input from the user, you need to use input() function.

e.g. >>> input("enter the string:") and + enter.
      >>> enter the string: "This is string" #you can add any string here.
output>>> 'This is string'

It is more similar to C and C++ languages. In C language we use scanf() function. In C++ we use cin>> function.

Next method is String Operations.

In python language, strings operations are simple to implement. lets get some examples.

Examples are:

>>>"23" + "26"
op>>> '2326'

>>> "23" * 3
op>>> '232323'

>>>"23" * "3"
op>>> type error...

--> First example shows that we can use we can add more than two strings in python.

--> Second example shows that if we can multiply a string with any numbers, we get new string length as per the multiplication.

--> It is important to note here in the third example that we can not multiply two strings or more than one string and also can not be multiply float numbers in python.

Next is type conversion.

We already know about type conversion in C and C++. Same concept are used in python.

>>> "2" + "2"
>>> '22'

>>>int("22")  + int("22")
>>> 44

we can convert any string into numerical by using type conversion.

Next is In-place operator:

In place operator is just like assignment operator,
e.g.
>>> x=3
>>> print (x)
op>>> 3
>>> x +=3
>>> print(x)
op>>> 6
  
Python gives a very useful feature like
>>> x=3
>>>print(x)
>>> 3

>>> x=4
>>> print (x)
>>> x=4

>>> del = x
>>> print (x)
>>> syntax error....
       
            If we are adding a value in x and then next time we added a new value in same variable x so that old value will be deleted permanently and we can use old variable x with new value. After completing our program we can use del statement for removing a variable x.

So this is it guys!!! stay tuned for more different updates follow us on here:


facebook: CLICK HERE!!!!!!!!!! 

Twitter: @NewAgeInformers

Instagram: @new_age_informers_
 


Comments