Python Learning Path, Day1–python Foundation 1

Source: Internet
Author: User
Tags split words

Written in the previous words:

After graduating from college did not engage in their own professional work, during the period also done a lot of work, now came to a logistics company, but every day of work, boring, boring, found that this is not what they want, they also have their own dreams, also have their own pursuit, think of Tiff Chobs said, Everyone should learn the technology of writing programs to the computer, because this process can teach you how to think!

In the vast programming language I chose Python, because it feels strong, applied to many fields, relative to other languages or with more simple, since the choice will go down, their choice of road, do not leave regrets.

The first day of Python learning

The content of this section:

    1. Python Introduction
    2. Python 3 Installation
    3. Python Development Tools Pycharm Installation
    4. First program "Hello World"
    5. Variable
    6. Strings and encodings
    7. User input
    8. Expression if...else-statement
    9. An expression for statement
    10. Break and Continue
    11. While

1.Python Introduction

  The founder of Python is Guido van Rossum (Guido van Rossum). During the Christmas of 1989, Guido van Rossum to spend time in Amsterdam, decided to develop a new script interpreter, as an inheritance of the ABC language.

The latest Tiobe leaderboards, Python overtaking C # occupy the four, Python advocating beautiful, clear, simple, is a good and widely used language.

Current Python main application areas:

    • Cloud Computing: the hottest language in cloud computing, typically using OpenStack
    • Web Development: A number of excellent web frameworks, many large sites are Python development, youtube,dropbox, watercress ... The typical framework has Django
    • Scientific Computing, artificial intelligence: Typical library numpy,matplstlib,enthought Librarys,pandas
    • system Operation and maintenance: the necessary language for operation and maintenance personnel
    • Finance: Quantitative trading, financial analysis
    • Graphical GUI: Pyqt,wxpython,tkinter

Python is used in some companies:

    • Google
    • Youtube
    • Dropbox
    • Douban
    • Know
    • Rain Doctor

2.Python 3 Installation

  Windows

1. Download the installation package

https://www.python.org/downloads/

2. Installation

Choose your own installation path

3. Configuration of environment variables

"Right button This computer"-"attribute"-"Advanced system Settings"-"Advanced"-"Environment variable"-"System variable"-"Find path line Edit"-"new"-"Python installation directory appended to the variable value"

3. Python Development Tools Pycharm Installation

  1. Download the installation package

https://www.jetbrains.com/pycharm/download/#section =windows

2. Installation

Choose your own installation path

3. Activated

1. Recommended purchase of Genuine

2. You can choose trial, free trial for 30 days

3. Find the Activation code online:

(The activation code below is from the Internet for learning and communication purposes only)

1. Modify the Hosts file:

Add the following line to the hosts file to block out pycharm validation of the activation code

              0.0.0.0 account.jetbrains.com

Windows System Hosts file path:c\windows\system32\drivers\etc

If you encounter permissions problems, you can copy the Hosts file first and then overwrite the original.

                After modification, check that the hosts file is valid

2. Open Pycharm and select Activate code

3. Copy and download the activation code, fill in the Activation Code box, click OK to authenticate.

1 Eb101iwswd-eyjsawnlbnnlswqioijfqjewmulxu1deiiwibgljzw5zzwvoyw1lijoibgfuihl1iiwiyxnzawduzwvoyw1lijoiiiwiyxnzawduzwvfbwfpb Ci6iiisimxpy2vuc2vszxn0cmljdglvbii6ikzvciblzhvjyxrpb25hbcb1c2ugb25sesisimnozwnrq29uy3vycmvudfvzzsi6zmfsc2usinbyb2r1y3rzij Pbeyjjb2rlijoisukilcjwywlkvxbubyi6ijiwmtgtmtatmtqifsx7imnvzguioijsuzailcjwywlkvxbubyi6ijiwmtgtmtatmtqifsx7imnvzguioijxuyi Sinbhawrvcfrvijoimjaxoc0xmc0xncj9lhsiy29kzsi6iljeiiwicgfpzfvwvg8ioiiymde4ltewlte0in0seyjjb2rlijoiukmilcjwywlkvxbubyi6ijiw Mtgtmtatmtqifsx7imnvzguioijeqyisinbhawrvcfrvijoimjaxoc0xmc0xncj9lhsiy29kzsi6ikrciiwicgfpzfvwvg8ioiiymde4ltewlte0in0seyjjb 2rlijoiuk0ilcjwywlkvxbubyi6ijiwmtgtmtatmtqifsx7imnvzguioijetsisinbhawrvcfrvijoimjaxoc0xmc0xncj9lhsiy29kzsi6ikfdiiwicgfpzf Vwvg8ioiiymde4ltewlte0in0seyjjb2rlijoirfboiiwicgfpzfvwvg8ioiiymde4ltewlte0in0seyjjb2rlijoiufmilcjwywlkvxbubyi6ijiwmtgtmta Tmtqifsx7imnvzguioijdtcisinbhawrvcfrvijoimjaxoc0xmc0xncj9lhsiy29kzsi6ilbdiiwicgfpzfvwvg8ioiiymde4ltewlte0in0seyjjb2rlijoi Ulnviiwicgfpzfvwvg8ioiiymde4ltewlte0in1dlcjoyxnoijoinjk0ndazmi8wiiwiz3jhy2vqzxjpb2reyxlzijowlcjhdxrvuhjvbg9uz2f0zwqiomzhbhnllcjpc0f1dg9qcm9sb25nyxrlzci6z mfsc2v9-gbb7jer8jwovxdufaxfjzvu/o7c7xhqyaidcnhylp7v32zdexihuu7vlrrm5y9zx0lmqk3plccsw+ phrc9ggapd6wdkhkal10qvng0larcr2tq3u8jfv1t2javwrmojffg9kksjuw1p4tozz/e7qvj1cupf/ rldhoomaxmyabxnn1af1rv3bvhe4ffze0p7xlijf/ctzkfk62hymh8v3ayhuntzrvk2k+t/ tldjz2lnw7nyttblhld8labpleejpthswhzlthzhvqaligvf0unbij5uwpb7nqr4u/2ob0z+ficrpfuiaheaw+rlgwkcge5dyzkfx+rorj/ in4q/upa==- Miiepjccaiagawibagibbtanbgkqhkig9w0baqsfadaymrywfaydvqqdda1kzxrqcm9mawxlienbmb4xdte1mtewmja4mje0ofoxdte4mtewmta4mje0ofowe tepma0ga1ueawwgchjvzdn5miibijanbgkqhkig9w0baqefaaocaq8amiibcgkcaqeaxcqkq+ zdxlr2mmrybpzgbundmn6oaxixzxiwtmekrjmo/5oufqjbllumsmk0qhfmai37wshyxzcfrcidwxjot4zmnbknlyhoddij/78tmvqfl8noed5+ 07b8veaiu7c3e1n+e1doc6wht4i4+iemtspadoaj5wcqvqbri8ket8m9vcbiwx7fd0fhexfg3zrt0xqwmcxgnp3ddjhio0rcdu+ itv7emtnsvq9jbg1usmsfvmowr25mju2jcpfp1+i4zi+fqgr8gyg8oindyneoabsr3lopi7gruysvkb/xvy/ Voklpck2h0f0gjxfjnye8nt1paywoyl7rmiavre/ekwidaqabo4gzmigwmakga1udewqcmaawhqydvr0obbyefgepg9ozgcflmgnbky7sghimggtcmegga1udiwrbmd+ afkoetkhnqhi2qb1t4lm0ofkll/ Gzorykgjaymrywfaydvqqdda1kzxrqcm9mawxlienbggka0myxg7kdeeewewydvr0lbawwcgyikwybbquhawewcwydvr0pbaqdagwgma0gcsqgsib3dqebcwu aa4icaqc9wzuygqedsuoc5tousrrigmw4/+wuc5etzbfvdl4ht/8vzmw/oulip4ycva0xkybacj2ix+zcdkopfiyxiasih+ hxapv6j79vvouxkrwg2xv6shftplp+0gpdgq3x9r3+kjbmam8w+fodlwqafjrlvpzmgnedu14ygxiz9bvzmiqbwrba+c/f4tlk/ dv07dsnexihqfoibnqdivntgombau2ddup2gwkdl81ua8eicgnexhe82kjf4zwfadhk3bqvvbfdawxcdy4xbjs3l4raplu3yenszr/oeur1+ jfoxnqsmecmxkxgraq9u55gwjcofkrgoxedek/sk1vfojvs+num4eyerufmfazhzoqiuw4iqggc45ohfh0uuyjycufxxdsu9lmcv8qdhkm+ wnprb0l9l5vxscbduhagyd6ss+ga+ady6f/qxzuuceuoh3qunbbculvisz6+girnt1ka9n2qachl+ 2ybfaquqr8h7z2gsx5lcif5kynsqj0gavxtvywh7pyikx4bs354zqluwwa/cg++2+wnwp+htbhvxmrntdvhsm38aknzld+ ptaswgu9gylmhti2envwgybsd2dxmhxk3ipckhkak+   pl0ewygzwg3tj9mz7sowcxlwdfak0lrjnkgfmtggrwjv8gypw5bq23vmiqqdlgknzuoog==

4. First program "Hello World"

    1. Open Pycharm, create a file named hello_world.py, and enter
    2. 1 Print ("Hello world! ")
    3. Execute command, output
    4. Hello world!

5. Variables

Rules for variable definitions

    • Variable names can contain only letters, numbers, and underscores. Variable names can begin with a letter or underscore, but cannot begin with a number, for example, a variable named message_1, but not 1_message.
    • Variable names cannot contain spaces, but you can use underscores to split words.
    • You can't use Python to keep a variable for a special-purpose word, for example, print,input ...
    • Variable names should be both brief and descriptive.
    • Use the lowercase letter L and the capital letter o sparingly.

  Reputation variables

#    -*-coding:utf-8-*-= "Dreams.lee"# This declares a variable, for name, with the value: "Dreams.lee"

Assigning values to variables

first_name = "Dreams"
Last_Name = ". Lee "
Print (first_name, last_name)
first_name = "Dreamsss"
Print (first_name, last_name)

Output

Dreams. Leedreamsss. Lee

6. Character encoding

When the Python interpreter loads the code for the. py file, the content is encoded (default ASCII)

ASCII code is a computer coding system based on the Latin alphabet, mainly used to display modern English and other Western European languages, which can only be represented by a maximum of 8 bits (one byte), that is: 2**8 = 256-1, so the ASCII code can only represent 255 symbols.

The ASCII code cannot represent all the words and symbols in the world, so a new encoding that can represent all the characters and symbols is needed, namely: Unicode

UTF-8, which is compression and optimization of Unicode encoding, does not use a minimum of 2 bytes, but instead classifies all characters and symbols: the contents of the ASCII code are saved in 1 bytes, the characters in Europe are guaranteed by 2 bytes

Save, East Asian characters are saved with 3 bytes ...

Therefore, when the Python interpreter loads the code in the. py file, the content is encoded (default Ascill).

# !/usr/bin/env python Print (" Hello!" ")

In 2.7, there will be an error.

Error: ASCII code cannot be expressed in Chinese

But in 3.5 you can do this, if you want the program to run correctly in 2.7 then you need to tell the Python interpreter what code to use to execute the source code, i.e.:

# !/usr/bin/env python # -*-coding:utf-8-*- Print (" Hello!" ")

7. User input

1 # !/usr/bin/env python 2 # -*-coding:utf-8-*- 3 4 username = input ("username:")5 password = input ("Password:")6 7 Print (Username,password)

8. Expression If...else

Scenario: guess Age

 1  my_age = 242  guese_age = Int (input ( Span style= "COLOR: #800000" > " guess_age:  "   3   If  guess_age == my_age:  4  print  ( "  Congratulations, you guessed it!   " )  5  else  :   6  print  ( "  Sorry, wrong guess!  ) 

9. An expression for loop

Scenario: Print Sequence 1-5

1 # !/usr/bin/env python 2 # -*-coding:utf-8-*- 3 4  for  in range (1, 6):5     print(i)

Output

12345

10.break and Continue

  Simple 5 cycles, printing numbers, but encountering less than 3 cycles will not go, jump directly into the next cycle

1 # !/usr/bin/env python 2 # -*-coding:utf-8-*- 3 4  for  in range (1, 6):5     if i < 3:6          Continue #结束当前循环, go to the next loop 7     else:8         print(i )

Output

345

  Simple 5 cycles, printing numbers, but encountering more than 4 cycles will not go, direct exit

1 # !/usr/bin/env python 2 # -*-coding:utf-8-*- 3 4  for  in range (1, 6):5     if i > 4:6          Break #不往下走直接跳出循环 7     else:8         print(i)

Output

1234

11. Expression while

Scene: Three chance to guess age

1 #!/usr/bin/env python2 #-*-coding:utf-8-*-3 4My_age = 245Count =06  whileCount < 3:7guess_age = Int (input ("Guess_age:"))8     ifGuess_age = =My_age:9         Print("Congratulations, you guessed it! ")Ten          Break One     elifGuess_age >My_age: A         Print("you're a big guess! ") -     Else: -         Print("you're a little guessing! ") theCount + = 1 -     ifCount = = 3: -Continue_game = input ("Do you still want to play? y/n:") -         ifContinue_game.title () = ="Y": +Count =0 -         Else:   break

Conclusion:

This is my first blog post, feeling written slowly, but very happy, in this way to record their learning, but also can share to everyone. Hope that they can persevere in learning Python, but also hope to seek everyone to work together. That's all for today, good night.

Python Learning Path, Day1–python Foundation 1

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.