. NET programmer python's Path---python basics

Source: Internet
Author: User
Tags ord python list

More curious about dynamic languages recently. So I chose to learn the language of Python. Don't say a word. Start learning notes.

  A. Python Basics:

1. Print data output to Python, #号后面是队友的输出结果, transcode characters by encoded, Ord gets the ASCII of the character,%s,%d is similar to the output of the C language, representing the string and the integer, respectively.

Print('Hello World')Print100+200# -Print1>2#falsePrint1>'2' #false#print ' abc ' +2 # errorPrintOrd'A')# $PrintU'Small Astute'. Encode ('Utf-8')Print 'name:%s,age:%d'%('Frank', 23)#name:frank,age:23 (%D->INT,%F->FLOAT,%S->STRING,%X->OXH)

Two. Usage of the Python collection:

Learn about C # and Java. The list,dictionary,arraylist in these two languages are very common, and in fact there are lists and dic in Python.

The use of 1.List. The list in Python is represented by [], where the list can have different types of data, which can be understood as List<object> in C #, where the list is different, like friendlist[-1] In fact, the return is friendlist[count-1], can be simply understood as a ring, subscript the range is-count<=n < Count. The second Python list also supports the sort (), append (), Remove () methods,

#List UsageFriendlist =['Frank','Loch','Hardy'];PrintFriendlist#[' Frank ', ' Loch ', ' Hardy ']PrintFriendlist.count#3Friendlist.append (1)PrintFriendlist;##[' Frank ', ' Loch ', ' Hardy ', 1] #若类型, equivalent to list<object> in C #PrintFRIENDLIST[-1]#1PrintFriendlist[-2]#HardyFriendlist.pop ();PrintFriendlist; ['Frank','Loch','Hardy']

The use of 2.Tuple. The Python tuple uses () to indicate that once the data for a tuple is declared, it cannot be modified and the data is read-only.

# tuple usage friendtuple = ("Frank","Loch"," Hardy " ) friendtuple#tuple data cannot be modified

3. Use of dictionaries. The Python dictionary is denoted by {}, and unlike C #, if there are multiple identical keys at the time of declaration, only the last one is saved. Del implements the deletion of the dictionary, Personinfo[keyname] implements the addition or modification of the dictionary. KeyName exists to modify the data, does not exist to add.

#DictionaryPersonInfo = {'Frank': 23,'Hardy': 24,'Loch': 26,'Loch': 25}Printpersoninfo['Loch']#25, the back of the cover front.personinfo['Victor'] =23PrintPersonInfo#{' Frank ': +, ' Loch ': +, ' Victor ': +, ' Hardy ':delpersoninfo['Victor']PrintPersonInfo#{' Frank ': Loch , ' Hardy ': +,}

4.Set usage, no list with the same element

# setMySet = Set ([1,2,3,3,3])print myset  #Set ([+)];

  

  Three. Python's loops and judgments.

Python does not like C # and Java this will put some code snippets with {} expansion, for Python with: number implementation of the parentheses function.

Note:print and if are not in the same column, which actually indicates that print is the sub-code of the If column, within the IF {}. It is not clear why this design, but used to the parentheses in C #, really think curly braces are more conducive to the readability of the code.

#Judging conditionsAge =10; Tupe usageifAge>60:    Print 'elderly'elifAge>18:    Print 'Adult'Else:    Print 'Young People'#LoopsNumlist = [1,2,3,4] forValinchnumlist:PrintVal

Summary: The above also on the most basic Python grammar, I believe that there is a C # foundation can be very easy to understand, language this thing or to be used often to be skilled, but the younger brother is only interested in the scholarship. The main places of study I still focus on the network programming python, I heard that Python network programming is also quite good (can do web crawler), do not know if this is the case. Let's learn it first. Personally, it is necessary to master at least one dynamic language. Learn about the differences between different languages.

. NET programmer python's Path---python basics

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.