Posts

Showing posts from August, 2017

Functions!

def defines the function returns none even if it is not going to return anything

All Tips!

Else in for: When having a condition in loop block, we may need to have a variable to set either the condition has been passed or not. Instead of that, Python provides "else" keyword to handle that. Else will only be executed, when the loop is executed completely without breaking out using "break" statement. eg., Finding the prime number in the range eg., This can be done as follows for n in range (2,10):     for x in range (2,n):          if n%x == 0:          break else:     print (" n is prime);

Control Flows:

Spl in Python!

Multiple assignments in a line! eg., a, b = 0, 1 conditions: All non-zeros are true, zeros are false if it is sequence, non-zero is true, empty seq is false eg., myList =[1,3,5] #true myEmptyList=[] # false

List!

List is a mutable type! List can hold different types! List can hold list itself! Works similar to string slicing! myList=[5,10,15,25,30] print(myList) # [5,10,15,25,30] myList[3]=20 print(myList)# [5,10,15,20,25,30] Nested Lists: myNestedList=[[4,2,1],[38,29,19]] print(myNestedList[1][1]) #picks up 1st Index list and then 1st index element

More on Strings!

Strings are str objects in Python and can be created using str constructor Strings are immutable , which means that, strings can be changed! Strings can be written in single, double or triple quote

Strings!

When want to print strings, we can just use single quote or double quote. eg., print("Hello World") print('Hello World') When we don't want to interpret the escape sequences, we can prefix the string with "r". This means raw string and would not interpret escape sequences. Usage of triple quotes... using triple quotes, we can print the multi lines as follows. print("""This is multiline text. Hence, this needs to be printed as it is as multline""") Python strings cannot be changed; word="Python" word[0]="T" #Not possible Error: str object does not support item assignment String indices: Starts from 0 to length-1 Also, we can traverse from last to first using negative indices starting from -1 to -length Slicing: Strings can be sliced.. slicing is nothing but getting substring using indices eg., word[2:] -> This will print the word starting from 3rd character till the end

Day 3: Programming Constructs

I have started looking into the various Python programming constructs. It is pretty easy. There is no much hard and fast rules. We can start executing the statements in Python command prompt only, as it is an interpreter one. Unlike Java, it does not have the job of compiling and running. Also, there is no need of flower bracket or any other brackets. Just an indentation will do to specify the blocks of the code! No need of terminating the statement by semicolon. We can keep writing the code. We can import modules using variety of ways to use it in our program. Python program extension is .py. There is no main method as we see in Java. It will start executing from the starting of the .py file.

Day 2: Python Installation and IDE

Python still supports both 2.x and 3.x. I selected Python 3.0. Then, was looking for good IDE. I tired Atom, PyCharm Community Edition and Eclipse plugin PyDev.  I am quite comfortable with both PyCharm and Eclipse with PyDev plugin. However, most of the time, I am using PyCharm. 

Day 1: Python!

It has been almost 2 weeks I started learning Python! Though I had started sometime earlier in bits and pieces, now I have a strong conviction to learn Python! I realized the power of Python when started learning! It is simple and at the same time so powerful! We don't need to follow several conditions as implied by traditional programming languages.  This is so simple that the code can be read and understood by anyone having minimum programming knowledge! That's was also a reason I was hesitant to learn Python earlier. I had some kind of mindset that if it is so easy, it would not do much powerful stuff.  However, literally, Python is so powerful that we can do almost anything! Right from file operations to game programming to web programming to data science...!  It is up to the individual what he wants to do!  The motivation behind my thought to learn Python is that I want to explore something on the data science. But after started working, I started