Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Python substring format     - Struts2 interceptor simulation (Programming)

- RedHat Performance Tuning (Server)

- MySQL password on those things you should know (Database)

- VMware virtual machine to use bridged mode fast Internet access (Linux)

- Element content of Java HashSet change issues (Programming)

- Several Methods of SSH Auto - login (Linux)

- Three minutes to teach you to easily grasp the grep command regular expression (Linux)

- Java rewrite the hashcode method (Programming)

- Repair Maven project developed default Maven Plugin folder (Linux)

- Use PDFBox parse PDF file (Linux)

- Linux Shell Scripting Interview Question (Linux)

- Nginx + uWSGI + Django + Python Application Architecture Deployment (Server)

- Using Lua implement various operations list (Programming)

- Ubuntu is not in the sudoers file problem solving (Linux)

- Offline (local) Yum source structures (Linux)

- Linux System Getting Started Tutorial: Using the Linux common commands (Linux)

- Linux network security probing tools Hping2 (Linux)

- Build your own Python coding environment (Linux)

- Depth understanding of the use of Spring Redis (Programming)

- Vi / Vim prompt solutions do not have permission to save time (Linux)

 
         
  Python substring format
     
  Add Date : 2017-01-08      
         
         
         
  Python substring format
usage:
{} And through: to replace the traditional way%
1, using the positional parameters
IMPORTANT: The following examples can be seen from the location parameter is not bound by the order and for {}, has long format parameter corresponding to the value of the parameter index from 0 to open a list of available parameters passed in location list *
>>> Li = [ 'hoho', 18]
>>> 'My name is {}, age {}'. Format ( 'hoho', 18)
'My name is hoho, age 18'
>>> 'My name is {1}, age {0}'. Format (10, 'hoho')
'My name is hoho, age 10'
>>> 'My name is {1}, age {0} {1}'. Format (10, 'hoho')
'My name is hoho, age 10 hoho'
>>> 'My name is {}, age {}'. Format (* li)
'My name is hoho, age 18'
2. Use keyword arguments
IMPORTANT: To get keywords value, the dictionary can be used as keyword argument values passed, the dictionary can be preceded by **
>>> Hash = { 'name': 'hoho', 'age': 18}
>>> 'My name is {name}, age is {age}'. Format (name = 'hoho', age = 19)
'My name is hoho, age is 19'
>>> 'My name is {name}, age is {age}'. Format (** hash)
'My name is hoho, age is 18'
3, filled with formatting
: [Fill characters] [Alignment < ^ >] [width]
>>> '{0: *> 10}'. Format (10) ## right-aligned
'******** 10'
>>> '{0: * <10}'. Format (10) ## Left
'10 ******** '
>>> '{0: * ^ 10}'. Format (10) ## centered
'**** 10 ****'
4, accuracy and hexadecimal
>>> '{0: .2f}'. Format (1/3)
'0.33'
>>> '{0: b}'. Format (10) # Binary
'1010'
>>> '{0: o}'. Format (10) # octal
'12'
>>> '{0: x}'. Format (10) # 16 hex
'A'
>>> '{:,}'. Format (12369132698) # thousands formatting
'12, 369,132,698 '
5, use the index
>>> Li
[ 'Hoho', 18]
>>> 'Name is {0 [0]} age is {0 [1]}'. Format (li)
'Name is hoho age is 18
     
         
         
         
  More:      
 
- VNC configuration detailed analysis under Linux (Linux)
- Set up MySQL master and slave servers under Ubuntu 14.04 (Server)
- Linux system started to learn: Teaches you install Ubuntu 15.04 on VirtualBox (Linux)
- Ubuntu 15.04 install Complete Guide (Linux)
- Large site architecture study notes (Server)
- Linux system installation and usage instructions Wetty (Linux)
- How to use nmap command in Linux (Linux)
- Firewall Configuration Red Hat Enterprise Linux 4 (Linux)
- Create the container and run the application Docker (Server)
- KVM virtualization of nested virtualization (Linux)
- Linux prohibit non-WHEEL user su command Detail (Linux)
- Linux operating system security settings initial understanding (Linux)
- RHEL6.4 one key installation Redmine (Linux)
- Java loop list to solve the problem of Joseph ring (Programming)
- After CentOS configure SSH password Free, still prompted for a password (Linux)
- Linux the best download manager uGet (Linux)
- SQLite database commonly used sentences and visualization tools on MAC MeasSQLlite use (Database)
- Linux 101 hack book reading notes (Linux)
- Hibernate learning introductory tutorial (Programming)
- Ubuntu Linux installation GAMIT10.6 (Linux)
     
           
     
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.