python 入門程序_非Python程序員的Python速成課程-如何快速入門

python 入門程序

This article is for people who already have experience in programming and want to learn Python quickly.

本文適用于已經有編程經驗并希望快速學習Python的人們。

I created this resource out of frustration when I couldn't find an online course or any other resource that taught Python to programmers who already knew other programming languages.

當我找不到在線課程或其他任何可以向已經了解其他編程語言的程序員教授Python的資源時,我無奈地創建了該資源。

In this course, I will be covering all the basics of Python (in-depth lessons will be added later on) so that you can get started with the language very quickly.

在本課程中,我將介紹Python的所有基礎知識(稍后將添加深入的課程),以便您可以快速入門該語言。

目錄 (Table of contents)

  • Setting up the environment

    搭建環境
  • Hello World

    你好,世界
  • Strings

    弦樂
  • Numbers

    號碼
  • Float

    浮動
  • Bool

    布爾
  • List

    清單
  • Tuple

    元組
  • Sets

    套裝
  • Dictionary

    字典
  • if..else

    如果別的
  • Loops

    循環
  • Functions

    功能
  • Classes

    班級
  • Modules

    模組
  • Truthy and Falsy values

    真實和虛假的價值觀
  • Exception handling

    異常處理

搭建環境 (Setting up the environment)

To get started, install Python 3. I recommend using VSCode as your editor. It has lots of extensions to configure so that you can setup your environment in just a few minutes.

首先,安裝Python3。我建議使用VSCode作為編輯器。 它具有許多可配置的擴展,因此您可以在幾分鐘內設置您的環境。

你好,世界 (Hello world)

print("Hello world")

If you already know programming basics, you'll probably know how to run this program :P. Save the program with the .py extension. Then run python hello.py or python3 hello.py.

如果您已經了解編程基礎知識,則可能會知道如何運行此程序:P。 使用.py擴展名保存程序。 然后運行python hello.pypython3 hello.py

In this whole tutorial, we will follow python3. python2 will be discontinued by 2020. So I think it’s good to go with the latest version.

在整個教程中,我們將遵循python3python2將于2020年停產。因此,我認為最好使用最新版本。

變量和數據類型 (Variables and data types)

Variables can contain letters, numbers, and underscores.

變量可以包含字母,數字和下劃線。

弦樂 (Strings)

# This is comment in Python
msg_from_computer = "Hello" # String
another_msg ='Hello in single quote' # This is also a String.print(msg_from_computer + " World..!")# Type will return the data type.
print(type(msg_from_computer)) # <type 'str'>. We will see the explanation of this later.

號碼 (Numbers)

2
2 * 3
2 ** 7
(2 + 3) * 4

浮點數 (Floats)

2.70.1 + 0.2 # 0.3
2 * 0.1 # 0.2

Be careful in Concatenation:

串聯時要小心:

count = 5print("I need" + count + "chocolates") # This line will throw error. As count is a integer, you have to type cast it.print("I need" + str(count) + "chocolates") # This will work

布爾 (Bool)

True # First letter is capsFalsebool("some value") # Returns Truebool("") # Returns Falsebool(1) # Returns True

清單 (List)

Lists are basically like arrays. In the Python world, they call them List. And they are ordered.

列表基本上就像數組。 在Python世界中,他們稱它們為List 。 他們被命令。

numbers = ["one", "two", "three"]numbers[0] # onenumbers[-1] # three. This is awesome. If we pass negative value Python will start from the end.numbers[-2] # twolen(numbers) # 3. It just returns the lengthnumbers.append("four") # Append will add the element to the last. ["one", "two", "three", "four"]numbers.insert(1, "wrong_one") # Insert will insert the particular value to the appropiate position. ["one", "wrong_one", "two", "three", "four"]# Deleting a value is somewhat weird
del numbers[1] # Will delete the value in the appropiate position. "one", "two", "three", "four"]# Pop will help you to remove the last element of an array
popped_element = numbers.pop()print(popped_element) # four
print(numbers) # ["one", "two", "three"]# Remove elements by value
numbers.remove("two") # ["one", "three"]. This will remove only the first occurence of an array.# Sorting
alpha = ["z", "c", "a"]
alpha.sort()
print(alpha) # ["a", "c", "z"] Sorting is permanent. now `alpha` is sorted permanentlyalpha.sort(reverse=True)
print(alpha) #["z", "c" , "a"] Reverse sorting.alpha = ["z", "c", "a"]
print(sorted(alpha)) # ["a", "c", "z"] This will just return the sorted array. It wont save the sorted array to the variable itself.print(alpha) # ["z", "c", "a"] As you can see, it's not sorted# Reversing an array
nums = [10, 1, 5]
nums.reverse()
print(nums) # [5, 1, 10] It just reverses an array. It means it reads from last. It's not sorting it. It's just changing the chronological order.# Slicing elements
alpha = ['a', 'b', 'c', 'd', 'e']
alpha[1:3] # ['b', 'c']. The first element is the starting index. And Python stops in the item before the second index.
alpha[2:5] # ['c', 'd', 'e']alpha[:4] # [ 'a', 'b', 'c', 'd'] In this case, the first index is not present, so Python startes from the beginning.alpha[:3] # ['a', 'b', 'c']alpha[3:] # ['d', 'e'] In this case, last index is not present. So it travels till the end of the list.alpha[:] # ['a', 'b', 'c', 'd', 'e'] There is no starting or ending index. So you know what happens. And this helps you in copying the entire array. I think I don't have to explain that if you copy the array, then any changes in the original array won't affect the copied array.another_alpha = alpha # This is not copying the array. Any changes in alpha will affect another_alpha too.

元組 (Tuples)

Tuples are just like lists but they are immutable. This means you can’t add or update them. You can just read elements. And remember, like lists, Tuples are also sequential.

元組就像列表一樣,但是它們是不可變的。 這意味著您無法添加或更新它們。 您可以閱讀元素。 記住,像列表一樣,元組也是順序的。

nums = (1, 2, 3)print(nums) # (1, 2, 3)print(nums[0]) # 1print(len(nums)) # 3empty_tuple = () # empty tuple. Length is zero.num = (1, ) # Note the trailing comma. When defining a single element in the tuple, consider adding a trailing comma.num = (1)
print(type(num)) # <type 'int'> It won't return a tuple. Because there is no trailing comma.# Creating a new tuple from the existing tuple
nums = (1, 2, 3)
char = ('a', )
new_tuple = nums + char
print(new_tuple) # (1, 2, 3, 'a')

套裝 (Sets)

Sets are unordered collections with no duplicate elements.

集是無序集合,沒有重復的元素。

alpha = {'a', 'b', 'c', 'a'}print(alpha) # set(['a', 'c', 'b']) As you can see, duplicates are removed in sets. And also the output is not ordered.# Accessing items in set
# You can't access by index because Sets are unordered. You can access it only by loop. Don't worry about the for loop, we will get that in-depth in the following section.
for ele in alpha:print(ele)# To add element into the set
alpha.add('s')# add can be used to insert only one element. If you want multiple elements, then update will be handy
alpha.update(['a', 'x', 'z']) # set(['a', 'c', 'b', 'x', 'z']) Remember duplicated are removed.# Length of the alpha
len(alpha) # 5# Remove the element from the set
alpha.remove('a')
alpha.discard('a') # It's safer to use discard than remove. Discard will never throw an error even if the element is not present in the set but remove will do.

辭典 (Dictionaries)

Dictionaries are key-value maps in Python. They're unordered.

字典是Python中的鍵值映射。 他們是無序的。

user = {'id': 1, 'name': 'John wick', 'email': 'john@gmail.com'}user['id'] # 1
user['name'] # John wick# Length of the dict
len(user) # 3# Add new key-value pair
user['age'] = 35# To get all the keys
keys = user.keys() # ['id', 'name', 'email', 'age']. This will return a list.# To get all the values
values = user.values() # [1, 'John wick', 'john@gmail.com']# To delete a key
del user['age']# Example of nested dict.
user = {'id': 1,'name': 'John wick','cars': ['audi', 'bmw', 'tesla'],'projects': [{'id': 10,'name': 'Project 1'},{'id': 11,'name': 'Project 2'}]
}# We will see, how to loop through the dict in for loop section.

如果別的 (if..else)

You likely already know how the if..else statement works. But let's see an example here:

您可能已經知道if..else語句如何工作。 但是讓我們在這里看一個例子:

a = 5
b = 10# See for the indentation. Indentations are very important in Python. Python will throw error if indentations are proper.
if a == 5:print('Awesome')# and is equivalent to && 
if a == 5 and b == 10:print('A is five and b is ten')# if else statement. This is same as most of the languages.
if a == 5:print('A is five')
elif a == 6:print('A is six')
elif a == 7:print('A is seven')
else:print('A is some number')# or is equivalent to ||
if a < 6 or a == 10:print('A should be less than 6 or should be equal to ten')# not is equivalent to !
if not a == 10:print('A is not equal to 10')# This is the short-hand notation of if statement.
if a == 5: print('A is five')# Short-hand for if-else statement.
print('A is five') if a == 5 else print('A is not five')

循環 (Loops)

Python has two types of loops:

Python有兩種類型的循環:

  1. For

    對于
  2. While

while循環 (while loops)

# The following while print till 5. Remember the indentation.
i = 0
while i <= 5:print(i)i += 1# Using brake or continue in while loop
i = 0
while i <= 5:print(i)i += 1if i == 2:break # You can try using continue here# Here comes the interesting part. While loop has else part. Else part will execute once the entire loop is completed.
i = 10
while i <= 15:print(i)i += 1
else:print('Completed')# Output
10
11
12
13
14
15
Completed# But if you are using break in the loop, then Python will break out of the entire loop and it won't execute else part.
i = 10
while i <= 15:print(i)i += 1if i == 13:break
else:print('Completed')# Output
10
11
12

對于循環 (For loops)

# For loops like for(i=0; i<5; i++) are not mostly used in Python. Instead, Python insists on iterating over itemsarr = ['a', 'b', 'c', 'd', 'e']
for ele in arr: # Prints every element in an arrayprint(ele)word = "python"
for char in word: # Prints every char in the wordprint(char)# You can use break, continue and else part in for-loop also.# When talking about for loops, I noticed that most resources have also mentioned about range() function. (We will deal with functions later part of this article.)# range() function will generates a sequence of numbers.# range(start, stop, step)
# start - optional, the starting number. Default is 0. This number is included in the sequence
# stop - mandatory, the ending number. This number is excluded in the sequence
# step - optional, increments by. Default is 1.range(3) # This code generates a sequences from 0 to 2.
range(1, 4) # This code generates a sequence from 1 to 3.
range(1, 8, 2) # This code generates a sequence with 1, 3, 5, 7for ele in range(3): # Prints from 0 to 2. print(ele)# In the below example, you can see I have used range to iterate through an array with index.
for index in range(0, len(arr)):print(arr[index])dict = {'name': 'John wick'}# You can iterate through a dictionary. items() will return both keys and values. You can also use keys() and values() if needed. 
for key, value in dict.items():print(key + " is " + value)# You can also use a built-in function enumerate(). enumurate() will return a tuple with index. It is mostly used to add a counter to the iterable objects in Python.
for index, value in enumerate(arr):print(value + " is present in " + str(index))

功能 (Functions)

def prints_hello_world():print('Hello world from Python')prints_hello_world()# Return statement
def prints_something(something):return something + ' from Python'print(prints_something('Hello world'))# If you pass wrong number of arguments like two or three arguments to this function then Python will throw an error.
print(prints_something())# Default parameter. I think its common in most languages now.
def prints_something(something = 'Hello world'):print(something + ' from Python')# keyword arguments. You can pass explicitly which parameter should be matched. In this way, you don't have to send the arguments in order just explicitly mention the parameter name.
def movie_info(title, director_name, ratings):print(title + " - " + director_name + " - " + ratings)movie_info(ratings='9/10', director_name='David Fincher', title='Fight Club')# Arbitrary number of arguments
# Sometimes, you dont know how many arguments are passed. In that case, you have ask Python to accept as many arguments as possible.def languages(*names):print(names) # ('Python', 'Ruby', 'JavaScript', 'Go'). This is a tuple.return 'You have mentioned '+ str(len(names))+ ' languages'print(languages('Python', 'Ruby', 'JavaScript', 'Go')) # You have mentioned 4 languagesdef languages(fav_language, *names):print(names) # ('Ruby', 'JavaScript', 'Go')return 'My favorite language is ' + fav_language+ '. And Im planning to learn other '+ str(len(names))+ ' languages too'print(languages('Python', 'Ruby', 'JavaScript', 'Go')) # My favorite language is Python. And Im planning to learn other 3 languages too# Arbitrary keyword arguments
# These types of arguments are useful when you don't know what kind of parameters are passed. In the previous case, it's useful when you don't know how many number of parameters are passed but in this case, you don't know what type of information will be passed.def user_info(**info):print(info) # {'id': 1, 'name': 'Srebalaji', 'fav_language': ['Python', 'Ruby']} This is a dictionary# Arbitrary keyword args will always expect to mention the parameters explicitly
user_info(id=1, name='Srebalaji', fav_language=['Python', 'Ruby'])# The below code will throw error. There is no keyword arguments.
user_info(1, 'Srebalaji')def user_info(id, name, **info):print(info) # {'fav_language': ['Python', 'Ruby'], 'twitter_handle': '@srebalaji'}user_info(1, 'Srebalaji', fav_language=['Python', 'Ruby'], twitter_handle='@srebalaji')

班級 (Classes)

# Python is general purpose and also object oriented language.# It's a convention that the class name starts with caps. But Python doesn't throw any error if you are not following it.
class Animal():# This is the constructor.# As you can see in every method of the class I have passed 'self' as the first parameter. The first parameter is always expected to be the current instance of the class and it is mandatory to pass the instance in the first parameter. And you can name that variable whatever you like.def __init__(self, name): self.name = namedef eat(self):print(self.name +' eats')def sleep(self):print(self.name+' sleeps')# Initiating a class
dog = Animal('harry')
dog.eat()print(dog.name) # As you can see, 'name' attribute is also avaiable in public. # It can even be modified.
dog.name = 'Rosie'
print(dog.name) # 'Rosie'# Technically there is no way to make private attrbiutes in Python. But there are some techniques Python devs are using it. I will try to list out some.# Protected attributes.
# These attributes can only be accessed within the class and also by the sub-class.class Person():# You can see that I have used different name for the first parameter.def __init__(my_instance, name):# 'name' attribute is protected.my_instance._name = namedef reads(my_instance):print(my_instance._name + ' reads')def writes(my_object):print(my_object._name + ' writes')person1 = Person('Ram')person1.reads()# But the worst part is that instance of the class can still access and change it :Pprint(person1._name) # 'Ram'person1._name = 'I can still change.'
print(person1._name) # I can still change# Protected can useful sometimes. Let's see how private attributes works. That can be a life saver sometimes.class Person():def __init__(self, name):# 'name' attribute is private.self.__name = namedef reads(self):print(self.__name + ' reads')def writes(self):print(self.__name + ' writes')# This is a private method. This can't be accessed outside the class.def __some_helper_method():print('Some helper method.')person1 = Person('Ram')
person1.reads() # Ram readsprint(person1.name) # Will throw an error. 'Person' object has no attribute 'name'print(person1.__name) # Will throw an error. 'Person' object has no attribute '__name'# Private attributes can only be accessed within the class. So it's safe. But still there is a catch :Pprint(person1._Person__name) # Ram.# You can even change the value
person1._Person__name = 'Hari'print(person1._Person__name) # Hari.# But every dev know that accessing and modifying the private attributes is a bad practice. And Python doesn't really have a clear restriction to avoid it. So you got to trust your peers on this.# Inheritanceclass Animal():def __init__(self, name):self.name = namedef eat(self):print('Animal eats')def sleep(self):print('Animal sleeps')# Dog is a sub class of Animal
class Dog(Animal):def __init__(self, name):self.name = namedef eat(self):print('Dog eats')dog1 = Dog('harry')
dog1.eat() # Dog eats
dog1.sleep() # Animal sleeps

模組 (Modules)

# Modules helps us to organise code in Python. You can split code in different files and in folders and can access them when you wanted.# Consider the below file. It has two functions.
# calculations.pydef add(a, b):return a + bdef substract(a, b):return a - b# consider another file which we consider as a main file.
# main.py
import calculationscalculations.add(5, 10) # 15
calculations.substract(10, 3) # 7# In the above example, you have imported the file and have accessed the functions in that.# There are other ways of importing.# You can change the method name if you want
import calculations as calc
calc.add(5, 10) # 15# You can import specific functions you need.
# You can access the function directly. You don't want to mention the module.
from calculations import add
add(5, 10) # 15# You can also import multiple functions
from calculations import add, multiple, divide# You can import all the functions
from calculations import *
add(10, 15)
multiple(4, 5)
divide(10, 3)# These will work for classes and variables too.

真實和虛假的價值觀 (Truthy and Falsy values)

# According to Python docs, any object can be tested truthy or falsy.# Below are the Truthy values
True
2 # Any numeric values other than 0
[1] # non-empty list
{'a': 1} # non-empty dict
'a' # non-empty string
{'a'} # non-empty Set# Below are the Falsy values
False
None
0 
0.0
[] # empty list
{} # empty dict
() # empty tuple
"" # empty string
range(0) # empty set# You can evaluate any object to bool using
bool(any_object) # returns True or False

異常處理 (Exception handling)

# The code which can raise exceptions can be wrapped in 'try' statement. 'except' will handle that exception.
try:some_error_raised
except:print('Exception handled')# Every exception in Python will inherit from 'exception' class. # In the below example, you can see that the 'NameError' is the exception class derived from the main 'Exception' class.
try:some_error_raised
except Exception as e:print('Exception raised')print(e.__class__) # <class 'NameError'># 'else' block will execute if the code in the 'try' block has raised no exception. This will be useful in many situations.try:some_error_raised
except:print('Exception handled')
else:print('No error raised. You can resume your operation here') # this code will execute if no error is raised in the 'try' block# final block
# Code in 'finally' block will execute no matter whether the exception is raised or not.
try:some_error_raised
except Exception as e:print('Exception raised')
else:print('This will execute if no error is raised in try')
finally:print('This code will run whether the code has error or not.')# Raise your own exception. You can also create your own exception class inherited from Exception class.
try:raise ZeroDivisionError # Python built-in exception class
except Exception as e:print(e.__class__) # <class 'ZeroDivisionError'># Catch a specific exception.
try:raise ZeroDivisionError # Python built-in exception class
except TypeError as e:print('Only type error exception is captured')
except ZeroDivisionError as e:print('Only zero division exception is captured')
except Exception as e:print('Other execeptions')

Thank you for reading :)

謝謝您的閱讀:)

Originally posted in this Github repo: Python crash course

最初發布在此Github存儲庫中: Python崩潰課程

翻譯自: https://www.freecodecamp.org/news/python-crash-course/

python 入門程序

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/390098.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/390098.shtml
英文地址,請注明出處:http://en.pswp.cn/news/390098.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

cmd命令操作Oracle數據庫

//注意cmd命令執行的密碼字符不能過于復雜 不能帶有特殊符號 以免執行不通過 譬如有&#xff01;#&#xffe5;%……&*之類的 所以在Oracle數據庫設置密碼是不要太復雜 /String Database "ORCL"; 不指向地址程序只能安裝在數據庫服務器上才能執行到命令String …

OpenCV學習(7.16)

寫了個實現攝像頭上畫線并輸出角度的東西……雖然很簡單&#xff0c;但腦殘的我還是debug了很長時間。 1 // 圓和直線.cpp : 定義控制臺應用程序的入口點。2 //3 4 #include "stdafx.h"5 6 using namespace std;7 using namespace cv;8 9 void onMouse(int event, in…

學習vue.js的自我梳理筆記

基本語法格式&#xff1a; <script> new Vue({ el: #app, data: { url: http://www.runoob.com } }) </script> 指令 【指令是帶有 v- 前綴的特殊屬性。】 判斷 <p v-if"seen">現在你看到我了</p> 參數 <a v-bind:href"url"&…

722. 刪除注釋

722. 刪除注釋 給一個 C 程序&#xff0c;刪除程序中的注釋。這個程序source是一個數組&#xff0c;其中source[i]表示第i行源碼。 這表示每行源碼由\n分隔。 在 C 中有兩種注釋風格&#xff0c;行內注釋和塊注釋。 字符串// 表示行注釋&#xff0c;表示//和其右側的其余字符…

如何創建一個自記錄的Makefile

My new favorite way to completely underuse a Makefile? Creating personalized, per-project repository workflow command aliases that you can check in.我最喜歡的完全沒用Makefile的方法&#xff1f; 創建個性化的按項目存儲庫工作流命令別名&#xff0c;您可以檢入。…

【BZOJ3262】陌上花開

CDQ分治模板 注意三元組完全相等的情況 1 #include<bits/stdc.h>2 using namespace std;3 const int N100010,K200010;4 int n,k,cnt[N],ans[N];5 struct Node{6 int a,b,c,id;7 bool operator<(const Node& k)const{8 if(bk.b&&ck.c) re…

Spring+jpaNo transactional EntityManager available

2019獨角獸企業重金招聘Python工程師標準>>> TransactionRequiredException: No transactional EntityManager availableEntityManager執行以下方法(refresh, persist, flush, joinTransaction, remove, merge) 都需要需要事務if (transactionRequiringMethods.cont…

python項目構建_通過構建4個項目來學習Python網絡

python項目構建The Python programming language is very capable when it comes to networking. Weve released a crash course on the freeCodeCamp.org YouTube channel that will help you learn the basics of networking in Python.當涉及到網絡時&#xff0c;Python編程…

164. 最大間距

164. 最大間距 給定一個無序的數組&#xff0c;找出數組在排序之后&#xff0c;相鄰元素之間最大的差值。 如果數組元素個數小于 2&#xff0c;則返回 0。 示例 1: 輸入: [3,6,9,1] 輸出: 3 解釋: 排序后的數組是 [1,3,6,9], 其中相鄰元素 (3,6) 和 (6,9) 之間都存在最大差…

10.32/10.33 rsync通過服務同步 10.34 linux系統日志 screen工具

通過后臺服務的方式在遠程主機上建立一個rsync的服務器&#xff0c;在服務器上配置好rsync的各種應用&#xff0c;然后將本機作為rsync的一個客戶端連接遠程的rsync服務器。在128主機上建立并配置rsync的配置文件/etc/rsyncd.conf,把你的rsyncd.conf編輯成以下內容&#xff1a;…

01_Struts2概述及環境搭建

1.Struts2概述&#xff1a;Struts2是一個用來開發MVC應用程序的框架。Struts2提供了web應用程序開發過程中一些常見問題的解決方案;對用戶輸入的數據進行合法性驗證統一的布局可擴展性國際化和本地化支持Ajax表單的重復提交文件的上傳和下載... ...2.Struts2相對于Struts1的優勢…

315. 計算右側小于當前元素的個數

315. 計算右側小于當前元素的個數 給定一個整數數組 nums&#xff0c;按要求返回一個新數組 counts。數組 counts 有該性質&#xff1a; counts[i] 的值是 nums[i] 右側小于 nums[i] 的元素的數量。 示例&#xff1a; 輸入&#xff1a;nums [5,2,6,1] 輸出&#xff1a;[2,1…

IOS上傳文件給java服務器,返回報錯unacceptable context-type:text/plain

IOS上傳文件給java服務器&#xff0c;返回報錯unacceptable context-type&#xff1a;text/plain response返回類型不對 RequestMapping(value "uploadMultiFiles", method RequestMethod.POST, produces"application/json;charsetUTF-8") 使用produces指…

Python爬蟲框架Scrapy學習筆記原創

字號scrapy [TOC] 開始 scrapy安裝 首先手動安裝windows版本的Twisted https://www.lfd.uci.edu/~gohlke/pythonlibs/#twisted pip install Twisted-18.4.0-cp36-cp36m-win_amd64.whl 安裝scrapy pip install -i https://pypi.douban.com/simple/ scrapy windows系統額外需要…

600. 不含連續1的非負整數

600. 不含連續1的非負整數 給定一個正整數 n&#xff0c;找出小于或等于 n 的非負整數中&#xff0c;其二進制表示不包含 連續的1 的個數。 示例 1:輸入: 5 輸出: 5 解釋: 下面是帶有相應二進制表示的非負整數< 5&#xff1a; 0 : 0 1 : 1 2 : 10 3 : 11 4 : 100 5 : 101…

高可用性、負載均衡的mysql集群解決方案

2019獨角獸企業重金招聘Python工程師標準>>> 一、為什么需要mysql集群&#xff1f; 一個龐大的分布式系統的性能瓶頸中&#xff0c;最脆弱的就是連接。連接有兩個&#xff0c;一個是客戶端與后端的連接&#xff0c;另一個是后端與數據庫的連接。簡單如圖下兩個藍色框…

Django的model查詢操作 與 查詢性能優化

Django的model查詢操作 與 查詢性能優化 1 如何 在做ORM查詢時 查看SQl的執行情況 (1) 最底層的 django.db.connection 在 django shell 中使用 python manage.py shell>>> from django.db import connection >>> Books.objects.all() >>> connect…

887. 雞蛋掉落

887. 雞蛋掉落 給你 k 枚相同的雞蛋&#xff0c;并可以使用一棟從第 1 層到第 n 層共有 n 層樓的建筑。 已知存在樓層 f &#xff0c;滿足 0 < f < n &#xff0c;任何從 高于 f 的樓層落下的雞蛋都會碎&#xff0c;從 f 樓層或比它低的樓層落下的雞蛋都不會破。 每次…

678. 有效的括號字符串

678. 有效的括號字符串 給定一個只包含三種字符的字符串&#xff1a;&#xff08; &#xff0c;&#xff09; 和 *&#xff0c;寫一個函數來檢驗這個字符串是否為有效字符串。有效字符串具有如下規則&#xff1a; 任何左括號 ( 必須有相應的右括號 )。任何右括號 ) 必須有相應…

Faster R-CNN代碼例子

主要參考文章&#xff1a;1&#xff0c;從編程實現角度學習Faster R-CNN&#xff08;附極簡實現&#xff09; 經常是做到一半發現收斂情況不理想&#xff0c;然后又回去看看這篇文章的細節。 另外兩篇&#xff1a; 2&#xff0c;Faster R-CNN學習總結 這個主要是解釋了18,…