Python knowledge points: How to modify the value of a global variable in a function?

Variables defined outside of functions are global variables.

Global variables can be read in functions, but by default the values ​​of variables cannot be modified in functions.

can read

The following code can successfully print the number of fans in the function, because the function can read the value of the global variable:

count = 30888 #全局变量,麦叔粉丝数

# 关注
def guanzhu():
    print('麦叔的粉丝数是{}'.format(count))

# 取关
def quguan():
    print('麦叔的粉丝数是{}'.format(count))

Can not be modified

The following code will report an error, because the function cannot modify the value of the global variable by default:

count = 30888 #麦叔粉丝数

# 关注
def guanzhu():
    count = count + 1
    print('麦叔的粉丝数是{}'.format(count))

# 取关
def quguan():
    count = count - 1
    print('麦叔的粉丝数是{}'.format(count))

Use the global keyword

In order to modify the value of a global variable in a function, you need to use the global keyword to declare the variable as a global variable at the beginning of the function.

This can be modified like this:

count = 30888 #麦叔粉丝数

# 关注
def guanzhu():
    global count
    count = count + 1
    print('麦叔的粉丝数是{}'.format(count))

# 取关
def quguan():
    global count
    count = count - 1
    print('麦叔的粉丝数是{}'.format(count))

Career Development

As a code wage earner, for the vast majority of programmers, there is still a long way to go to become an awesome real money-making programmer, and they can't slack off for a moment.

We cannot guess which state of the interview is more favored by the interviewer from the perspective of HR or the technical leader. But through the large amount of interview experience we have accumulated, you can more or less infer some of the necessary conditions to become a competitive programmer.

Gathering of bigwigs and rich information

At the beginning, I met a very, very senior senior in Byte. He came to Byte three years earlier than me, but his level was not very high for various reasons. I asked him at the time, since you are so dissatisfied with the status quo, why don't you think about leaving to find better opportunities?

He pondered for a moment and told me that although my stay here is not going well, the people I have come into contact with are all excellent. I have a problem, and I can discuss it with you. If I go out, if I encounter problems again, there may not even be anyone to discuss.

I just thought it made sense when I heard it at the time, but looking back now, I feel very profound. Three outlooks, structure, ability, those who can enter a large company, these three aspects are generally not too bad. Among other things, in terms of personal ability, I have traveled abroad for several months, and I have been fortunate enough to meet many colleagues from various famous overseas schools, and learn and communicate with them on artificial intelligence. This really gave me a deeper understanding of AI. know.

In addition to excellent colleagues, large companies often have rich internal documents and materials. At that time, I saw many excellent articles inside Byte, and there were also many excellent technical salons and sharing. Now that I think about it, I haven’t been there a few times in the past two years, and I haven’t read too many articles and materials. It’s a pity now that I think about it. Among other things, as far as the field of recommendation is concerned, the papers with good quality in recent years often come from large companies, especially large domestic companies, mainly Tencent, Huawei and Toutiao. In addition to the public papers, there are a lot of technology-related materials and documents within the company. These are really valuable and have no market, and are very precious.

Python Knowledge Manual

Linux Knowledge Manual

The crawler query manual

Moreover, these materials are not scanned versions, and the text inside can be copied directly, which is very convenient for us to learn:

Data Analysis Knowledge Manual:

Machine Learning Knowledge Handbook:

Handbook of Financial Quantitative Knowledge:

Job referral, learning exchange

We need a large number of front-end positions, python positions, Java positions, Android and iOS development positions, working location: Beijing Byte, welcome school recruiters to scan the QR code below and find me to recommend

Python information, technology, courses, answers, consultation can also directly click on the business card below,添加官方客服斯琪

Guess you like

Origin blog.csdn.net/Python_cocola/article/details/123284517