Start Python(part 1)

figureprint

  • Why continue learningprint?
  • printWhen you write a program, what does it bring?
  • How to learn && use gracefullyprint?
  • .
  • So with those questions, let’s move onprint

1. Single print

print "I'm going to print a message."
Copy the code

2. Multiple prints (original print format)

print """ I'm going to print out multiple messages and guess what... It's over. """

# Same way to achieve the above effects
print 'I'm going to print out several messages \n guess what \n is \n... \n It's over '
Copy the code

3. Print with parameters

print 'this is a %r' % 'book'

print 'This is a book %s' % 'book' # If there is an error here. Think about the character encoding Settings from last time
Copy the code

4.%r%s

Let’s run a piece of code and see what the difference is.

# coding=utf-8
print 'Here are the formatting arguments for %r'
test_param = '%r %r'
print test_param % ('oh'.'hei')
print test_param % (test_param, test_param)

print '-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --'

print 'Here are the formatting arguments for %s'
test_param1 = '%s %s'
print test_param1 % ('oh'.'hei')
print test_param1 % (test_param1, test_param1)
Copy the code

In debugging, %r is used more often, because %r displays the raw data values of variable types, such as strings with single quotes; Chinese output is not normal. %s is more often used when the output is actually needed.

5. Print multiple times*

print The '*' * 4

# Actual output: ****
Copy the code

6..The application of

What is the difference between the following code?

print 'hello '.'world'

print '-- -- -- -- -- -- -- -- -- -- -- -- --'

print 'hello '
print 'world'

Copy the code

7. Translation characters

  • \translation
  • \nA newline
  • \tLock into