ezoic

Wednesday, July 13, 2016

How to pratically learn python from zero: chapter two basics

First, to learn some basic concepts etc, you need a good tutorial, like below:

http://www.tutorialspoint.com/python/


Like many programming language, python uses some computer command to let computer finish some work for ppl. The work can be some computing work, can be software development.

To finish the work, one needs to learn how Python denote numbers, strings, vectors etc. Or in other words what kind of data structures python has.

Python use variable to denote different types of data.

It has several data types:

1. Number

counter=5

Assign 5 to counter. After that, once we refer ti counter, we mean a variable with value 5. 


2.String

string1="Alice"

Put the letters, numbers etc in a single or double quote, and assign to a variable. This variable will have a value in the quote.

Python's single quote, double quote and triple quotes have some different usages.

Here is an article talking about the three quotes:

http://faculty.tarleton.edu/agapie/documents/cs102_intro/lab01_gettingstarted_python2.pdf


3.List

List is like a vector in Python. It put a list of data into a "[]".

The elements in a list can be anything, numbers, strings etc.

list1=[1,2,3,'ak','oop',99]

We can add, remove elements from list. And we can iterate on a list.

add element:

cc="aa"
list1.append(cc)

remove element:

list1.remove('ak')



4.Tuple

Tuple is something included in a "()". And once we create a tuple. We can not alter it like list.

tuple1=(1,2,"wi")


5.Dictionary (hash table in Python)

Dictionary is quoted in "{}". It is some pairs of keys and values. And the keys are unique in a dictionary. I.e. the dictionary's keys can not have duplicates. Otherwise, you will have some error. And each key can have anything as the value, including the list etc.


Dict={"Name":"Alice", "Age": 7, "Height": "6"}

And we can refer to the values of the keys in a dictionary like this:

print Dict['Name']

And the values in a dictionary can be changed.



And you can set up a dictionary by  starting from a empty dictionary.

dic2={}

dic2["game name"]="football"
dic2["number of ppl"]=22
...

And then you can set up a dictionary from an empty dictionary.




Dictionary is a very powerful data type.  It is very useful. And if you analyze some messy data, you will use it a lot maybe.

There is another data type in python. It is called set. It is a list of elements. And the elements are all unique. So we can use set to calculate/get the unique elements in a list.




Operators in Python"

One also needs to know how python do the calculations, +,-,*,/. And it has a modular arithmetic "%".  The modular arithmetic may be different for positive and negative numbers.

The results of the dividing will be determined by the signs of both numbers. If the signs of the both numbers are same, then the results will be positive, otherwise it will be negative.

The results of the modular arithmetic will be determined by the signs of second numbers. If the sign of the second numbers is positive , then the result will be positive, otherwise it will be negative.

And python also has the operator like power. "**".



There are some other operators in Python too. Like the comparison operator, bitwise operators etc.

No comments:

Post a Comment

looking for a man

 I am a mid aged woman. I live in southern california.  I was born in 1980. I do not have any kid. no compliacted dating.  I am looking for ...