Introduction To Python
Python is simple, easy to use, interpreted programming language, offering much more structure and support for large programs than shell scripts or
batch files can offer. Being a very-high-level language, it has high-level data types built in, such as flexible arrays and dictionaries. Because
of its more general data types Python is applicable to a much larger problem domain.
As Python is an interpreted language, which can save you considerable time during program development because no compilation and linking is necessary.
Python allows you to split your program into modules that can be reused in other Python programs. It comes with a large collection of standard modules
that you can use as the basis of your programs or as examples to start learning to program in Python. Some of these modules provide things like file I/O,
system calls, sockets, and even interfaces to graphical user interface toolkits like Tk.
Python also has Web Development Frameworks like Django, Flask and Pyramid. It can also be used for automation with tools like Robot Framework, Selenium and Ansible.
Comments In Python
A Comments starts with "#" (Hash) in python. It is the part which is not executed, i.e It is ignored by Interpreter.Indentation
In Python, Unlike C, Java We don't use Curly brackets {}. Here Spaces Or In python Indentation Matters.A Step Towards Programming
Now, We will Write Classic Hello World Program.Their is Difference in Python 2.x & 3.x in function print.
2.x Version of Our Program is
print "Hello World From Python"
3.x Version of Our Program is
print("Hello World From Python")That's It. Output:
Hello World From PythonYou can take input by using methods input() or raw_input().
>>> n = input('Enter the limit: ') Enter the limit: 9You can check type of variable using type()
>>> type(n) <type 'int'>
>>> s = raw_input('Enter something: ') Enter something: PythonYou can also check type of this using type()
>>> type(s) <type 'str'>
Now, We will perform some math on two number,
Addition
Addition
>>> 2 + 3 5Subtraction
>>> 5 - 2 3Division
>>> 8 / 2 4Multiplication
>>> 3 * 7 21
Playing with Strings
String can be 'Single Quoted' or "Double Quoted">>> s = 'Hello World'Then s will print string 'Hello World'
'\' Can be used as escape sequence Character
>>> print 'isn\'t it?' isn't it?You can write Single Quoted String in Double Quoted & Vice Versa.
>>> 'This is "Double Quoted" with single quotes' 'This is "Double Quoted" with single quotes' >>> "This is 'Single Quoted' with Double quotes" "This is 'Single Quoted' with Double quotes" >>> len(s) 6len() will return length of String
>>> s[0] 'H' >>> s[6:] 'World' >>> s[0:5] 'Hello' >>> s[::-1] 'dlroW olleH'Can be used to reverse the String.
List - A Data Structure
List is Data structure in python, like Array. But Unlike String and Array, which are 'Immutable' list is 'Mutable'. It store items separated by comma(,), It might contain items of same type or different types.>>> team = [3, 9, 11, 19, 37] >>> team [3, 9, 11, 19, 37] >>> team[1] 9 >>> team[-1] 37 >>> team[2] = 91 >>> team [ 3, 9, 91, 19, 37] >>> team.append('b') >>> team [ 3, 9, 91, 19, 37, 'b'] >>> team.pop() 'b'This is just introduction. We will see this in detail, Keep Following
Wow, So simple
ReplyDelete