020000_python Getting Started

Source: Internet
Author: User
Tags string format

First, why Choose Python?

1, Python is the pursuit of finding the best solution, in contrast, other languages are pursuing a variety of solutions.

2, Python's greatest advantage is that you can focus on solving problems rather than understanding the language itself.

Second, variable and string

1. Variables

Variables are the most basic unit of storage in programming, and variables temporarily store what you put in.

The name of the variable is called an identifier.

Python is case sensitive, "a" and "a" are two different variables.

2. Print ()

Printing is the most common feature in Python.

Hump Naming method

Pascal name Law

3. String

Single quotes, double quotes, three quotation marks

Basic use of strings--merging

1 '  '2'guitar'3'Robert Johnson ' 4 Artist_intro = his_name + what_he_does + his_instrument5print#  Robert Johnson plays guitar

Type () function to see the types of variables

Because the Chinese note will be typing error, so you need to add a line of Magic Note # Coding=utf-8 at the beginning of the file, you can also find in the settings "File encodings" set to UTF-8

Data type conversions

1 num = 12'1'3 num2 = int (string)4Print  #  2

    

String multiplication

1 ' words ' * 32print#  wordswordswords
1 Word ='a loooooong word'2 num =123'bang! ' 4 # This means total = ' bang ' * (16-12) 5 Print # bang!bang!bang!bang!

  

Partitioning and indexing of strings

The string can be indexed, string[x, and partitioned by means of a [].

Each string obtained by a shard (slice) can be considered a copy of the original string.

1Name ='My name is Mike'2 Print(Name[0])#M3 Print(Name[-4])#M4 Print(Name[11:14])#Mik5 Print(Name[11:15])#Mike6 Print(name[5:])#Me is Mike7 Print(Name[:5])#My na8 " "9 1: The two sides represent the string of the sub-given is where to start, and where to end. Ten 2, take name[11:14] For example, the intercept number starts with the 11th character and ends with a position of 14 but excluding the 14th character.  One 3, like name[5:] This notation represents the character from 5 to the end of the string shard.  A 4, like Name[:5] represents the beginning of a character numbered from 0 to a character with a number 5, excluding the 5th character of the Shard - " "

  

Find the Devil in your friend

1 ' Friends ' 2 find_the_evil_in_your_friends = word[0] + word[2:4] + word[-3:-1]3print (find_the_evil_in_your_friends)  # fiend

  

Applications in real-world projects

  

Method of String

Python is a language for object-oriented programming, and objects have a variety of functions, features, and terminology called-method.

Hide Information

1 ' 1386-666-0006 ' 2 ' * ' * 9)3' is used here with the new string method replace () for "occlusion", the Replace method in parentheses, the first phone_number[ : 9] Represents the part to be replaced,4 after the ' * ' 9 means a brief replacement of what character, that is, the * multiplied by 9, showing 9  *"5 Print (Hiding_number)  # *********0006

  

Analog phone number Lenovo function in phonebook

1Search ='168'2Num_a ='1386-168-0006'3Num_b ='1681-222-0006'4 Print(Search +' is at'+ STR (num_a.find (search) + 1) +' to'+str (Num_a.find (search) + len (search)) +'of Num_a')5 #168 is at 6 to 8 of Num_a6 7 Print(Search +' is at'+ STR (num_b.find (search) + 1) +' to'+str (Num_b.find (search) + len (search)) +'of Num_b')8 #168 is at 1 to 3 of Num_b

string format characters

You can use. Format () to batch when there is more than one "empty" in the string that needs to be filled in.

Blank questions

____ A word she can get what she ___ for.

1 Print('{} A word she can get what she {} for.'. Format (' with','came'))2 Print('{preposition} A word she can get what she {verb} for.'. Format (preposition=' with', verb='came'))3 #preposition prepositions, verb verbs4 Print('{0} A word she can get what she {1} for.'. Format (' with','came'))

Using the weather API provided by Baidu to implement the development of the client weather plugin code snippet

1 city = input ("writedown the name of City:")2" Http://apistore.baidu.com/microservice/weather?citypinyin={}.format (city) "

Three, the most basic magic function

1. Re-recognize functions

Print is a function that puts the result in an object to print

Input is a function that lets the user enter information

Len is a function that can measure the length of an object

int is a function that converts a number of string types to a certificate type

The so-called use function in Python is to put the object you are dealing with in parentheses within a name.

The built-in functions (Bulit-int Functions), which can be used after the installation is complete, are "self-bringing".

2. Start creating functions

The meaning of Def (that is, define, definition) is to create functions, that is, to define a function.

Arg (i.e. argument, parameter), and the other is parameter.

return returns the result.

    

020000_python Getting Started

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.