, try to get it ecactly riht print ("If I add%d,%d, and%d I get%d."% (age, height, weight, Age + height + weight)
The results of the operation are as follows:
$ python ex5.py let
' s talk about Zed A. Shaw.
He's inches tall.
He ' s 180 pounds heavy.
Actually that ' s not too heavy.
He ' s got Blue eyes and Brown hair.
His teeth are usually white depending on the coffee.
If I add, and 180 I get 289.
$
Python portal, print, basic data, variables
Where does the code begin?
(1) Python is executed from the time the first script is loaded.Python test.py(2) In the script to call the other script inside the code and dataRelated code, put it in a. py file, irrelevant to the different. Py, a. PY can call other.
Exercise 5 mainly reviews the use of variables in the previous exercise and uses the formatting characters for the first time.
The code is as follows:
My_name = ' Zed A. Shaw '
my_age = #not a lie
my_height = #inch
my_weight = 180 #lbs
my_eyes = ' Blue ' C4/>my_teeth = ' White '
my_hair = ' Brown '
print ("Let's" talk about my%s. "%my_name)
print" He's%d inchs
The sharing and release of python class variables under multiple threads has recently been put into the trap by multiple threads. I am not aware that class variables are shared under multiple threads. Another problem is that I am
to what type is low (always list)It is important to note that an asterisk expression is useful when iterating over a sequence of elements that are variable-length tuples. Like whatRecords = [('Foo', 1, 2),('Bar','Hello'),('Foo', 3, 4),]defDo_foo (x, y):Print('Foo', x, y)defDo_bar (s):Print('Bar', s) forTag,*argsinchRecords:ifTag = ='Foo': Do_foo (*args)elifTag = ='Bar': Do_bar (*args) output: Foo1 2Bar Hel
Assigning multiple values at the same time is a cool programming shortcut: In Python, you can use tuples to assign multiple values at a time. Multiple values are assigned at the same time.
The following is a cool programming shortcut: In Python, you can use tuples once.
Ass
function return multiple values:Supplementary Knowledge Points: Write code to get less use of global variables:1. Unsafe2. Will always occupy the memory does not releasefunction multiple return values, the return values are placed in a tuple and returned 1 def Hello (a,b,c,d): 2 return a,b,c,d 3 Res=hello ( " YBQ , " ede , " RFV , " deq " ) 4
Assigning multiple values at the same time
Here's a cool programming shortcut: In Python, you can use tuples to
Assigns multiple values.
>>> v = (' A ', 2, True)
>>> (x, y, z) = V①
>>> x
A
>>> y
2
>>> Z
True
1. V is a ternary tuple, and (x, Y, z) is a meta with three variables
Group. Assigning one of the values to ano
There is a loss of value after stitching multiple variables in a single script run.A = "Hello"b = "Ketty"c = A + B + "!"Expected output is Hello ketty!The actual output is!How the script works: Python runtime plus a filename A as a parameter, the Python script runtime reads the data inside a file for parsing, the conte
In general, the dynamic output of HTML content in PHP is achieved through print and ECHO statements, and in practice, both print and ECHO functions are almost identical. It can be said that there is a place to use, and the other can be used. However, there is also a very important difference between the two: in the Echo function, you can output multiple strings a
Print multiple triangles in cycles and print triangles in cycles
Print a row *. It's easy to print.
The Code is as follows:
1 public class Work10_3 {2 3/** 4 * @ param args 5 */6 public static void main (String [] args) {7 // TODO Auto-generated method stub 8 int a = 0; 9
the scope.
X = 100 def foo(): global X print 'foo() x = ',X X = X + 5 print 'Changed in foo(), x = ',X def fun(): global X print 'fun() x = ',X X = X + 1 print 'Changed in fun(), x = ',X if __name__ == '__main__': foo() fun() print 'Result x = ',X
The output res
Notes for using class variables and member variables in python: python Variables
Preface
Recently I was writing a project in python and found a disgusting bug, that is, the data between two instances generated by the same class co
# define a variable xprint (id (x) # The variable x is a new variable print (x + 5) # The name is the same, however, the new variable x is used.
Continue assignment
x = 'hello python'print(id(x))print(x)
At this time, x becomes a new variable, and the variable type also changes due to the change of the assigned data type.
Here, id () is a Python built-in functio
variable. That is, in many cases, the parameters and variables in the function do not need to be so differentiated and the truth is that you only need to know the channel through which the object is transmitted and the target of the object.
To make it clearer that the args (names can be different, but the symbols must be), we can use the following simple function to demonstrate it:Copy codeThe Code is as follows:>>> Def foo (* args ):...
function when it finishes executing. At the same time, the return value will be assigned to the 10th line of the equal sign to the left of the C variable, next to the 11th line, print the sum of results, after the execution of 11 lines, the main is completed after the full execution of the next line of 13th line 14th line to print out the string ' end! ', to the end of the program.With the basic concept of
Whether it is class-based face-to-face object programming or the definition of internal variables of simple functions, the scope of variables is always a step that must be understood in Python learning, next we will start to fully parse the scope of variables in Python from
Starting from local variables and global variables, the scope of variables in Python is fully parsed.
Understand global variables and local variables1. If the variable name in the defined function appears for the first time and before the = symbol, it can be considered as a
Whether it is a class-based face object programming, or a simple function of the definition of internal variables, the scope of the variable is always a Python learning must understand the link, the following we start from the local variables and global variables to fully parse the scope of the
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.