Learning Diary | 5.18 [Python3] Python3 basics and Object-oriented

Source: Internet
Author: User

Note: This is a series of network training based on the experimental Python learning diary, the content is scattered, just for my own review, it is necessary to understand www.shiyanlou.com.

1. GitHub-related

The first is to review GitHub related operations:

1.1 Complete creation of accounts and warehouses

Log in to github.com, create new repository, and initialize readme.md automatically.

1.2 Using Ssh-keygen to generate a public private key

The recommended key is saved in the default location: Terminal input Ssh-keygen, the default Save key location is/home/shiyanlou/.ssh/id_rsa, all the way to enter. Then use Ls-a to see the hidden files, enter. SSH you can see two files named Id_rsa (private key) and id_rsa.pub (public key).

Open the SSH and GPG keys item in GitHub user settings and paste the public key contents into it.

1.3 Configuring Git Tools

1 git--version                              # Check whether git has been installed2 sudo apt-get install git-y                # install git3 git con Fig--global user.name "username"   # For example, xxxx01014 git config--global user.email "useremail"  
     

Open GitHub's repository, copy the SSH link to the Clipboard, and enter the following command:

1 CD "Yourfolder" 2 git clone "xxxxxxxxxx"   # Copied link 3 cd "Yourreponame" 4 # Create with Echo or touch 5 # Then
   
     add these new files 6 git add "newfilename" 7 # Delete file 8 git rm "Somefile" 9 # Restore the file11 git reset--
    
     # commit after change14 git commit-m "Your activity/change description" # use M when commit for the first time  15 # then
      push, and change the repo17 git push-#check the CHANGES20 git fetch Origin   
    
   

2. Experimental 3:python Basic grammar

Create a file with Vim circle.py and edit:

#!/usr/bin/env python3# The first line is called Shebang, telling the Shell to use Python3 to execute the code
From math import pi# calculateresult = 5 * 5 * piprint (Result)

When you are finished, enter chmod +x circle.py to add permissions and use./circle.py to execute.

Enter multiple lines of string using three "to resolve.

Strip () Remove the end-to-end, split () cut word.

Break represents a stop cycle, and continue represents skipping the current wheel loop.

Using try except finally catches the exception, and finally is the code that executes regardless of the situation, for example:

filename = '/etc/protocols 'f = open (filename) try:    f.write (' Shiyanlou ') except:    print (" File write Error ") finally: print (" finally ") f.close ()       

Query the module search path using the following method:

Import Syssys.path

Each of the. py files is a module.

If you want to identify a folder as a package, this folder needs to have __init__.py files, the content can be empty, you can use the Import folder (package) name. File (module) name to introduce.

Get "command line arguments" with the sys.argv of the SYS module:

#!/usr/bin/env python3import sysprint(len (SYS.ARGV)) for Arg in sys.argv:    print (ARG)  

Execution Result:

$ python3 argtest.py Hello shiyanlou3argtest.py     # argv[0]         Hello          # Argv[1]shiyanlou      # Argv[2]

The __name__ property of each Python file defaults to its own file name without the. Py form, such as Hello.py's __name__ property is hello. When executing this file with the Python interpreter in the terminal, the value of __name__ becomes __main__. When this file is poured into another file as a module, __name__ remains the default.

Learning Diary | 5.18 [Python3] Python3 basics and Object-oriented

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.