Python basics-for Loop (use for loop to print 9-9 multiplication tables of different formats), python --
# Square output 9-9 multiplication table for I in range (): for j in range ):# % 2d is used to place the result of multiplication in two places. The output result is more elegant. After all, some results are single digits, and some are ten digits, reserved spa
it mean? That is to say, % s calls the str () function to convert the object to the str type, while % r calls repr () to convert the object to a string. For the differences between the two, see Difference between str and repr in Python. The following is a simple example to illustrate the differences between the two:
Copy codeThe Code is as follows:>>> Import datetime>>> Today = datetime. date. today ()>>> TodayDatetime. date (2014, 8, 15)>>> Str (tod
%s"% ("Aviad")) #His name is aviad# prints integer print ("He is%d years old"%) #He was years old Lt;pre name= "code" class= "Python" >print ("He is%d years old"%) #He is a years old# print floating-point printing ("his height is%f M "% (1.83)) #His height is 1.83 m# print
One,%, or format1,%, Format Imperial PKThe format string in Python currently has two camps:% and format, which one should we choose?Since Python2.6 introduced the format-formatted string method, I think the% or format is not a pro
Format the python string and format the python string.
Most of the time, when printing input content, we want a simple format instead of splicing.
General Practice:
1 name = input("name:").strip()2 age = input("age:").strip()3 job = input("job:").strip()4
Some basic usage of print is also involved in the previous article. This article focuses on the basis of the review and try to add as much content as possible.
Eval ()
Let's take a look at this stuff before we print it. It is not useless, because it may be used in some cases.
The code is as follows:
>>> Help (eval) # This is a rare concept. if you don't understand how to use it, use this document.
Help o
eval ()
Before print does anything, look at this stuff first. It's not useless, because it might be used at some point.
Copy the Code code as follows:
>>> Help (eval) #这个是一招鲜, if you don't understand how to use it, use this to read the document
Help on built-in function eval in module __builtin__:
Eval (...)Eval (source[, globals[, locals]), value
Evaluate the source in the context of globals and locals.The source may be a string representing a
convert the object to a string. Please refer to the difference between the two: difference between STR and repr in Python, here is a simple example to illustrate the difference between the two:
Copy Code code as follows:
>>> Import datetime
>>> today = Datetime.date.today ()
>>> today
Datetime.date (2014, 8, 15)
>>> Str (today)
' 2014-08-15 '
>>> repr (today)
' Datetime.date (2014, 8, 15) '
Finally, to express
, and only the result of all true,and operations is True.An OR operation is an operation, as long as one of the true,or operation results is True.The not operation is a non-operation, which is a single-mesh operator that turns true to False,false to true.Five, null valueThe null value is a special value in Python, denoted by none. None cannot be understood as 0, because 0 is meaningful, and none is a special null value.The
Python _ does not need to print 1-1000 cyclically, and python prints 1-1000Question: I can print the 1000 numbers from 1 to on the screen. Do not use cyclic or conditional statements. Do not use them? : Operator. You are not allowed to use the method of listing output statements in the source code. For example, if you
this print statement?
The code is as follows:
$ Python fib. py-s 1-e 100Cur: 0, start: 1, end: 100Cur: 1, start: 1 and end: 100Returning result 11 Before caculation: a, B = 0, 1After caculation: a, B = 1, 1Cur: 1, start: 1 and end: 100............(Countless output information)
As you can see, all the computing processes are printed out.
Print is added when wri
;> print (t) (1, 2, 'A') >>> d = {'A': 1, 'B': 2 }# dictionary >>> print (d) {'A': 1, 'B': 2}
2. format the output integer
Python string formatting symbol:
Letter Number
Description
% C
Format characters and their ASCII codes
% S
The output print function summarizes:1. String and numeric typescan be directly output[Python]View PlainCopy
>>> Print (1)
1
>>> Print ("Hello World")
Hello World
2. VariablesNo matter what type, value, Boolean, List, dictionary ... can be directly output[
Baptism of the soul, practice python (3) -- expose coding problems, operating principles and syntax habits from a simple print code, pythonprint
After the preliminary work is ready, you can open the IDE editor. You can select the built-in python IDLE or a third party. Here I use pycharm-an IDE dedicated to python.
By c
Don't say a word, just cut to the chase.The print statement can output the specified text to the screen. For example, the output of ' Hello, world ', implemented in code as follows:>>> print ' Hello, world 'Attention:1. When we write code in a python interactive environment,,>>> is the prompt for the Python interpreter
Basic Python tutorial 2-3: print a sentence in the "box" with the correct width. Basic python tutorial
Sample Code:# Obtain the sentence lengthSentence = input ('plese input a sentence: ') # He's very naughty boyScreen_width = 100# Getting the length of TextText_width = len (sentence)# Text widthBox_width = text_width + 10# Calculate the number of free formats on
follows:
$ python fib.py-s 1-e 100
cur:0, Start:1, end:100
Cur:1, Start:1, end:100
Returning result 1
1 before caculation:a, b = 0, 1
After caculation:a, B = 1, 1
Cur:1, Start:1, end:100
... ...
... ...
(Countless output information)
As you can see, all the calculations are printed out.
When you write with print, you have to remember to delete the
characters into the next variable in the parameter list
Use of basic methods: 1 #!/usr/bin/python 2 #coding =utf-8 3 "4 You can specify the alignment of the desired length of the string: 5 #!/usr/bin/python#coding=utf-8# use the ' {} ' placeholder print (' I\ ' m {},{} ') using the Str.format () function #. Format
Python format function, python string format
1. The format can accept infinite parameters, and the positions can be unordered:
In [1]: "{}{}". format ("hello", "world") # do not set the location, In the default order Out [1]: 'Hel
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.