In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces what is the use of functions and variables in Python. It is very detailed and has a certain reference value. Interested friends must finish reading it!
First, let's take a look at this code demonstration to understand the relationship between functions and variables in Python:
Def cheese_and_crackers (cheese_count, boxes_of_crackers):
Print "You have d cheeses!" cheese_count
Print "You have d boxes of crackers!" boxes_of_crackers
Print "Man that's enough for a party!"
Print "Get a blanket.\ n"
Print "We can just give the function numbers directly:"
Cheese_and_crackers (20,30)
Print "OR, we can use variables from our script:"
Amount_of_cheese = 10
Amount_of_crackers = 50
Cheese_and_crackers (amount_of_cheese, amount_of_crackers)
Print "We can even do math inside too:"
Cheese_and_crackers (10 + 20,5 + 6)
Print "And we can combine the two, variables and math:"
Cheese_and_crackers (amount_of_cheese + 100, amount_of_crackers + 1000)
Through this case, we can find that the function cheese_and_crackers passes a lot of parameters and then prints them out in the function. We can use variable names in functions, we can do operations in functions, and we can even combine variables with operations. On the one hand, the parameters of the function are similar to the = assignment we use to generate variables. In fact, if you can name something with =, you can also pass it as an argument to a function.
Let's take a look at the terminal output of the code we just wrote:
$python ex19.py
We can just give the function numbers directly:
You have 20 cheeses!
You have 30 boxes of crackers!
Man that's enough for a party!
Get a blanket.
OR, we can use variables from our script:
You have 10 cheeses!
You have 50 boxes of crackers!
Man that's enough for a party!
Get a blanket.
We can even do math inside too:
You have 30 cheeses!
You have 11 boxes of crackers!
Man that's enough for a party!
Get a blanket.
And we can combine the two, variables and math:
You have 110 cheeses!
You have 1050 boxes of crackers!
Man that's enough for a party!
Get a blanket.
These are all the contents of the article "what are functions and variables in Python?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.