Python Basic Learning

What is Python:
Python is an interpreted, object-oriented, high-level programming language with dynamic semantics.

Python Interactive shell
At first we will learn python interactive shell uses. You can start interpreter from IDLE.

Python interpreter:
The Python interpreter is a command line program:

>>> print 'hello world'
Hello world
>>> 2+2
4
>>> 50-20
30
>>> 5*5
25
>>> 30/6
5
>>> x = 5
>>> y = 10
>>> print x+y
15

Comments:
Single line comment: A single line comment starts with the number sign (#) character:

# This is a comment
print('Hello')

Multiline comment: Multiple lines can be created by repeating the number sign several times:

# This is a comment
# second line
# 3rd line
print('Hello')

Variables in Python can hold text and numbers.

var = 2
hello = 2.5
country = 'Bangladesh'

type() is a function:

>>> country = "Bangladesh"
>>> print country
Bangladesh
>>> type(country)
<type 'str'>
>>> var = 2.5
>>> print var
2.5
>>> type(var)
<type 'float'>

if you want to exit from python interactive shell

exit()

String uses: Strings in Python can be defined using quote symbols

>>> country = "Bangladesh"
>>> print country
Bangladesh
>>> str = "Adam's"
>>> print str
Adam's
>>> hello = 'Adam\'s'
>>> print hello
Adam's
>>> 

Accesing array elements: You may access character elements of a string using the brackets symbol. Computers start counting from zero

>>> country = "Bangladesh"
>>> print country [0]
B
>>> print country [2]
n
>>> 

String length: builtin function len()

>>> len(country)
10
>>> print country [9]
h

Let us look at some string operations. We can add two string

>>> country = 'Bangla' + 'desh'
>>> country
'Bangladesh'
>>> 

The string did not have anything, that i can do with find() method.

>>> country.find('Bangla')
0
>>> country.find('desh')
6
>>>