程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Oeasy teaches you to play with Python - 9 - newline characters

編輯:Python

Newline characters

Recall the last time

  • The number system can be transformed into

    • bin(n) You can convert numbers into 2 Base number
    • hex(n) You can convert numbers into 16 Base number
    • int(n) You can convert numbers into 10 Base number
  • Encoding and decoding can be transformed into

    • encode code
    • decode decode
  • ASCII Code table range

    • 0x41-0x5A This range is Big Write letters
    • 0x61-0x7A This range is Small Write letters
    • 0x30-0x39 This range is Numbers

      • The coding of numbers minus 0x30 Just get the number itself
    • 0x20-0x7F There are various symbols between
    • 0x00-0x1F What is the thing between ?

File encoding

  • Write a document

    • write down abcd
    • use :%!xxd
    • :%!xxd -r Change back

  • You can see that the file is in 2 Base number Mode stored

    • 0x61 - a
    • 0x62 - b
    • 0x63 - c
    • 0x64 - d
  • The one in the back 0a What is it?
  • We have to go back to the beginning

Back to the original

  • Let's go back to the beginning
  • Previously introduced c The first program of language
  • be aware hello world hinder \n Why? ?

    • be aware hello world hinder \n Why? ?
    • Pay special attention to the direction of the slash
    • In this direction \ It's called a backslash
    • On the return
  • that \n What is it ??

Output "\n"

# Output \n
print("\n")
# direct print
print()
# Look at the ordinal number
ord("\n")
# Check the hexadecimal serial number
hex(ord("\n"))
  • Let's just output him
  • Seems to have changed two That's ok
  • If not \n Words , Change only One That's ok
  • \n As a whole as a character

    • The serial number is (10)10 Base number
    • That is to say (0x0A)16 Base number

Find a place

  • 10 It's hexadecimal 0x0A
  • This value is in ascii The code table means LF
  • What do you mean by that? ?

Search for

  • Search for \n The result is like this

    • LF signify Line Feed Hello, Yixing ?
  • Then I can really use this \n Change your career ?

# Output string with \n
print("Hello\nWorld")

  • The line change is successful !

A few more

# Output string with \n
print("He\nllo\nWor\nld")
  • Obviously this \n It's just a line feed

    • There is a... In the string \n It means you need to change 1 That's ok
    • His English is Line Feed
    • It means New 1 That's ok
    • This thing is actually better than ascii It has a long history
    • From the era of typewriters
  • At the beginning, paragraphs are divided by outputting spaces and then wrapping

    • Ever since I had this
    • One key has a new line
    • therefore LineFeed Very efficient

The inverse

# Output ascii The value is 10 The characters of
chr(10)
# Put this character in print It outputs
print("hello"+chr(10)+"world")

Go back to history

  • Earliest c Language Medium \n From what ?

    • From B Language
    • B Language It was first developed by rich and Thompson unix Language
    • He runs in bell laboratory Of PDP-8 On
    • 1969 It was originally used in B Language
  • 1971 Since, for B Language To transform

    • In the newly bought PDP-11 On the use of B to B Write extensions , be called NewB
    • 1973 In, the main body will be basically completed , Change the name to c Language
    • They use the compiler and language at hand to PDP-11 Rewritten a Unix Kernel
    • Machine language and assembly language are not portable
  • c Language The program can be used in Any architecture On the processor

    • As long as the processor of that architecture has the corresponding c Language compilers and Libraries
    • Then cross platform compilation can be realized
    • That's what we call cross compilation today
    • This is it. c Language The reason why it could develop at that time

  • B Language Nor was it created out of thin air
  • B What does language come from ?

Basic Combined Programming Language(BCPL)

  • B Language comes from BCPL(Basic Combined Programming Language)

    • 1967 By the University of Cambridge Matin Richards Make
    • Also developed by Cambridge University CPL Language Improved from
    • BCPL It was first used as the of Oxford University OS6 operating system The above development tools
  • Later, through the improvement and promotion of Bell Laboratories in the United States, it became UNIX Common development languages on

    • Earliest BCPL The language looks like this
    • This is the notation The earliest record ever recorded
    • There is a similar 、 what n Things that are
    • What did the line break look like at that time ?

BCPL The newline for

  • This is the newline character at that time

    • !*n

summary

  • \n It's line changing

    • He corresponds to ascii The code of the character is (10)10 Base number
    • His English is LF, intend Line Feed
  • So I can freely control where to change my line !

    • Can you make the following frame title ?
    • Let's talk about it next time !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved