Hi , Its a quick tutorial and I have only 7 minutes of your precious time So lets start without any further ado.
Installing Python :
- If you are on Linux or Mac Machine Python is already installed on your system .
- On Windows system Simply to the https://www.python.org/downloads/ and download the version 2.7.x where x can be anything(My case 9) , see the image below for further reference.
- Just add Python to you Path on windows using this Link
Hello World Saga :
[python] print("Hello World") [/python]
Data Type , Strings with Syntax
Basic syntax is same any other programming language like Java , The data structures available in python are lists, tuples and dictionaries. Sets module provides classes for constructing and manipulating unordered collections of unique elements. Common uses include removing duplicates from a sequence.
- Lists are like one-dimensional arrays (but you can also have lists of other lists). Tuples are immutable one-dimensional arrays
- Dictionaries are associative arrays (a.k.a. hash tables)
- Strings – Strings are immutable in python , Below image shows how you can assign a variable with String value and Concatenate it with other data types like Int , Boolean etc.
## This is how you take a range in python
myrange = range(10)
for item in myrange:
if item in (1,3,5,7,9): ## if item % 2 == 0 for other logic
item = 1
while item < 10:
item = item+1
[code] Output : range(0, 10) Even Number Old Number Even Number Old Number Even Number Old Number Even Number Old Number Even Number Old Number
1 2 3 4 5 6 7 8 9 [/code]
Functions and Claases
print("Hi I am Function")
myText = "How are you"
if __name__== "__main__":
myObj = myClass() ## Creating Object
myValue = myObj.myFucntionWithArguments(1,2)
[code] Hi I am Function
# Division by zero raises an exception
10 / 0
print "Oops, invalid."
# Exception didn’t occur, we’re good.
# This is executed after the code block is run
# and all exceptions have been handled, even
# if a new exception is raised while handling.
print "We’re done with that."
We’re done with that.
‘This is the first line of the file.n’
for line in f:
I hope I was able to give you a quick glimpse of Python in 7 minutes. Please leave comments if you believe there is something that could be improved or added or if there is anything else you would like to see.