Python Basics

Before starting reading this blog make sure you have installed latest Python IDLE.

If not go to Downloads and follow the given steps.

This Post will have basic Python statements to start with Python IDLE.

Few instructions are given below try typing it in your IDLE to understand how Python works.

At the end of post you will get few practice questions.

So lets start Pythonior's.......

 Step 1: Open Python IDLE

Step 2 : Start typing below statements.

Simple Calculation 

>>> 3+4  (press enter after every statement)
7
>>> 3*9
27
>>> 5/2
2.5
>>>6-2
4
Python Basics, Simple Calculation

Compound Statement

>>>(2+4)*(3/2)
9.0
Python Basics, Compound Statement

Variable Assigning

>>> x=5+6

It will not show anything but will remember value of x=11

Similarly,
>>>y=2*4

Now, if you type
>>> x + y
19        (result of adding two variable)

Python Basics, Variable assigning

String

String is series of characters

>>>"Hello"
'Hello'

For typing string single or double quotation can be used.

>>> x = 'dog' .................. (Combination of String and Variable)
>>> x
'dog'

Python Basics, String

Print Statement

>>>print(4)
4

>>> print('hello')
hello

>>>print('dog',5,6,'cat')
dog 5 6 cat

>>>print(x)
dog

>>> z = 'John'
>>> age = 30
>>> print("My name is",z,"and my age is", age)
My name is John and my age is 30

Python Basics, Print

Restart IDLE

If you want Python to forget all the above used variable then go to
Shell -------> Restart Shell-------> click it

When you restart Python Shell it will forget all the values stored in any variable. 

So try typing.....

>>> print(x)

It will give you error.

Python Basics, Restart Shell

Summary

  • Python can be used as Calculator.
  • Use of variables to store values
  • Define a String
  • Use of Print Statement to display values.

Examples:-

x=2.0
print(x)


x=2.0
y=1
z=x+y
print(z)


x=(24*2)/4
y=2.3
print(x(y*3))

x="John"
print("Hello",x)


x="cat"
y="dog"
x=2
print(x,y)


Practice above examples.....


Comments

Popular Post

Python Data Types

Python String

Python List