程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python from introduction to project practice -- basic syntax

編輯:Python

List of articles

`


List of articles

  • List of articles
  • Preface
    • Python Is a complete computer programming language , be based on c Language development implementation , And can call c The function library provided by the , from python It has just been born with a perfect syntax structure and program support library , In the age of big data ,Python It is widely used in data analysis and artificial intelligence development .
  • One 、Python Characteristics of language
  • Two 、Python Compiler download and installation
    • 2.python Programming starts
  • summary


Preface

Python Is a complete computer programming language , be based on c Language development implementation , And can call c The function library provided by the , from python It has just been born with a perfect syntax structure and program support library , In the age of big data ,Python It is widely used in data analysis and artificial intelligence development .

One 、Python Characteristics of language

(1).Python The grammar of a language is simple and flexible . Comparison C Language ,c++ and java Equal compiled language ,Python It seems simple .
(2). Normalized code
(3).Python It's an open source project , Free to developers .
(4).Python Is a programming language for object-oriented programming .
(5). Portability makes program development easier .
(6).Python It's an interpretative language
(7). Strong scalability
(8). It has a rich development support library
(9). Good concurrency support
however Python There are also many shortcomings , For example, the running speed is slow , Incompatible development versions, etc . I am based on Python 3.x Development . If a friend is using 2.x edition , You can change .

Two 、Python Compiler download and installation

Python There are a lot of compilers for , One of them visual studio code,psycharm And other compilers are very good compiler software , Here I introduce vs code.
VSCode( Full name :Visual Studio Code) Is a cross platform free source code editor developed by Microsoft ,VSCode The development environment is very simple and easy to use .

VSCode It's easy to install , Open the website https://code.visualstudio.com/, Download the package , Step by step installation , Pay attention to the installation path setting during installation 、 Environment variables are automatically added to the system by default , Check all of the following options :


Create a Python Code file
open VScode, Click New... And then click :

Click to select language :


Enter in the search box Python, Choose Python Options :

Enter the code :

print(“Runoob”)
Right click mouse , Choose to run the file in an interactive window , If prompted to install extensions , Just click to install ( If there is no installation, it will always be displayed in the connection Python kernel ):

in addition , We can also open an existing file or directory ( Folder ), Let's open one runoob-test, You can also create one yourself :

And then we create one test.py file , Click the new file icon below , Input file name test.py:


Then you can write code , And then run ;

2.python Programming starts

We installed the compiler , Let's start writing our first code :

# coding:UTF-8
infors=[1,2,3,4,5,6,7,8]
print("%d" % max(infors))
print("%d" % sum(infors))
print("%d" % (min(infors)))
print("%d" % (len(infors)))
print("%s" % (all(infors)))
print("%s" % any(infors))
# character string 
# String fragmentation operation 
del infors
infors="if i like you,i was The heart moves with it "
sun_name=infors[:5]
su_name=infors[4:]
print("%s" % (sun_name))
print("%s" % (su_name))
""" stay python Chinese characters and letters in a string are treated as one character . Chinese characters are two bytes , The letter is a byte , therefore , stay In the actual program , During string interception , Especially the interception of Chinese , You must record the number of bytes intercepted , Once the garrison is intercepted , There will be a problem of garbled code . """
''' UTF-8 code , English and English punctuation occupy one byte , Chinese characters and Chinese punctuation occupy three bytes . Unicode code ( Hexadecimal code ) Chinese and Chinese punctuation occupy two bytes , English also takes up two bytes . '''
# String information statistics 
title="www.ccc.com"
print(" String length :%d" % (len(title)))
print(" The largest character in a string :%c" % (max(title)))
print(" The smallest character in a string :%c" % (min(title)))
# The use of member operators 
if "www" in title:
print(" There is ")
# String formatting ;
name="lihua"
score=100
print(f"{
name} {
score}") #{} Used for occupying ;
print("%(name)s %(score)d" % vars()) # Dictionaries ;
''' grammar : “{ Member tag ! Transformation format : Format description }”.format( parameter list ) '''
del name
print("{name!s:^20}" .format(name="lihua"))
infors=12345678
print("{infors:,}".format(infors=12345678))
del infors
infors=190.456
print("{item:.2}".format(item=infors)) # Retain two digits of precision ;

Many of the above functions have not been introduced yet , This is just to familiarize you with the operation of the compiler , It will be described in detail later .
put questions to : In the above program, we will find , The program starts with “# coding:UTF-8” What does that mean ? What is his function ?
answer : In the computer world, all file information is stored on disk or transmitted through the network in the form of coding , Correct coding settings can prevent the occurrence of ” The statement “,Python In order to simplify the , Set it at the head :

# coding: Code name 
Common code names are GBK,GB2312,UTF-8;
What is used here is UTF-8 code , Learn formally later Python Programming knowledge , Will introduce why to use UTF-8 code , Not the others .

summary

This section mainly explains the compiler download , Skilled use of compilers can often save us time , If there is no foundation , You can follow the above tutorial step by step , Some people use psycharm compiler , It all depends on one's will , It will not affect the later study .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved