Comparison of Python3 and Netcore basic syntax (string column)

Source: Internet
Author: User

Comparison of Python3 and Netcore basic syntax: https://www.cnblogs.com/dunitian/p/9103673.html

Color version of the latest version: Https://www.cnblogs.com/dunitian/p/9119986.html

Make a statement beforehand, avoid getting the novice into the misunderstanding: not to say that Python is better than netcore, and the purpose of python design is = = "Let the programmer free, do not pay too much attention to the code itself, then the performance, specifications and other aspects of the hidden dangers exist, Writing a slightly larger item behind it can be seen. And do not be too constrained by language, I have said before, with the advantages of their own language for the Project Services ~ This is the development of the kingly way. For example, Python for data analysis, go for concurrent processing and so on, not much to say, remember a word:"NET is the most cost-effective"

come to the point: Welcome to a simpler or more efficient approach

Basic series: (This is the point of Python, the last thing I said, I took a stroke)

1. Output + type conversionPython notation:

Netcore:

2. String splicing + splicing output mode

Python:

Netcore

3. String traversal, subscript, slice

The key point of the Python subscript, a little meaning, the last element, we are generally len (str)-1, he can directly use -1, pour 2 naturally is -2

#最后一个元素: User_str[-1]user_str[-1]user_str[len (USER_STR)-1] #其他编程语言写法 # Reciprocal second element: User_str[-2]

This time in order to more image contrast, a sentence translated into Netcore ( there is no law, user_str[user_str. length-1]== "-1 is the last, User_str[user_str. length-2]== "-2 is the last one. Python is simplified in this regard. )

3.2 Python slicing syntax : [Start_index:end_index:step] (End_index not taken)

# slice: [Start_index:end_index:step] (End_index not get) # Eg:str[1:4] Take str[1], str[2], str[3]# eg:str[2:] Remove the element labeled 2 start to Last # Eg:str [2:-1] Remove the second element labeled 2~ to the penultimate (End_index not) # Eg:str[1:6:2], ~str[1], str[3] (case will be detailed) # Str[5] Reverse output (case will be detailed,)

Here's a case: My comment section is very detailed, the appendix will be affixed DemoCode

Netcore, in fact, you use Python and other languages contrast more contrast, net really very powerful. Supplement (see Why Python step is 2, i+=2== 2)

Method Series:

# Find: Find,rfind,index,rindexPython Find recommended you use Find and RFindNetcore: index0fIt's the equivalent of Python. Find # counts: countPython: Str.count ()Netcore: This really uses the foundation to solve, can only transform oneself: (Original string length-replacement length)/String lengthPython add-on: Like these methods practice using Ipython3Just Fine ( sudo apt-get install Ipython3, code words need one by one print, more trouble (my side because need to write an article, so can only a code) index lookup no exception # Replacement: ReplacePython: xxx.replace (str1, str2, number of replacements)Replace can specify several substitutions

Netcore: Replace a specified number of times the function is a bit amateur, don't say, you can think for yourself oh ~

#连接: Join:eg:print ("-". Join (Test_list))

Netcore:string. Join (delimiter, array)

#分割: Split (split by specified character), Splitlines (split by Row), partition (divided by Str into three parts, before STR, str and STR), rpartition

Next, Split's slice usage: print (test_input.split ("", 3)) #在第三个空格处切片, the back is not cut

Keep talking. Splitlines(split by Row), and split ("\ n") The difference in my diagram gives the case extension: split (), by default cut by a null character (space, \ t, \ n, etc., don't worry about returning ")Finally, say something. PartitionAnd R PartitionThe return is the Ganso type (which will be said later), just like find, find the first match and strike out "notice the case not found" Netcore: split inside a lot of overloaded methods, you can go to see under, eg:split ("\ n", stringsplitoptions.removeemptyentries) Say this again: Test_str. Split (' a ');//return arrayif you want to return the list = = as Python test_str. Split (' a '). ToList (); "need to reference LINQ namespaces Oh" # The Tail judgment: startswith (... Beginning), EndsWith (with ... End)

Netcore:

# Case series: lower (string converted to lowercase), upper (string converted to uppercase), title (capitalized in Word), capitalize (first character uppercase, other lowercase)

Netcore:

# Format series: Lstrip (remove left space), Rstrip (remove the right space), strip (remove the space on both sides) beautify the output series: Ljust,rjust,centerNetcore: Tirm is very powerful, except to go to the space can also remove any character you want to removeLjust,rjust,center These are not said, Python often output in the Linux terminal, so these are used more. NET inside string. FormatAll kinds of formatted output, you can refer to # Verification Series: Isalpha (whether it is a pure letter), isalnum (whether it is a number | letter), ISDIGIT (whether it is a pure number), isspace (whether it is a pure space)A picture is done, others to try it, pay attention to Oh ~ test_str5= "\ t \ n" #isspace () ==>trueNetcore:string. IsNullOrEmptyand string. IsnullorwhitespaceIs the system comes with, the other you need to encapsulate an extension class (eg: Simple package) "Appendix"

Appendix:

Python3:

View Code View Code

Netcore:

View Code

Simple package:

View Code

say so much basically almost finished, the next list + dictionary + meta-group to talk about AH ~

Comparison of Python3 and Netcore basic syntax (string column)

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.