Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ Python maketrans () method     - Linux file permissions and access modes (Linux)

- Android custom title bar (Programming)

- RHEL5.x RHEL6.x replace CentOS yum source (Linux)

- Orionode source Linux Mint installation (Linux)

- How to write a new Git protocol (Linux)

- Local port forwarding using iptables under linux (Server)

- Source MongoDB 3.2.1 installed on CentOS6.5 (Database)

- CentOS / Linux NIC set IP address configuration (Linux)

- How do you turn on and off IPv6 address on Fedora (Linux)

- How to install Zephyr Test Management Tools on CentOS 7.x (Server)

- Linux scheduling summary (Linux)

- Proxmox VE implement KVM OpenVZ virtualization cloud computing (Server)

- When Linux virtual machine to another copy of the operating system, a static IP NAT mode Invalid (Linux)

- OpenWrt modify flash size (Linux)

- Linux Command Study Notes (Linux)

- Windows 8.1 and Ubuntu 14.04 dual system uninstall Ubuntu Tutorial (Linux)

- Go build the locale under Windows (Linux)

- 8 Git tips (Linux)

- W and uptime command (Linux)

- CentOS 7 RHEL 7 to reset the root password (Linux)

  Python maketrans () method
  Add Date : 2018-11-21      


Python maketrans () method is used to create character mappings conversion table, for taking two parameters, the easiest way is called, the first argument is a string that represents the character to be converted, the second argument is a string indicating that the conversion goal.

NOTE: The two strings must be the same length as a one to one relationship.


maketrans () method syntax:

str.maketrans (intab, outtab)

• intab - string consisting of the string to replace characters. Character string corresponding mapping - outtab;

The return value

new string Returns string conversion after generation.


The following example demonstrates the use of maketrans () method to convert all vowels specified number:

#! / Usr / bin / python

# - * - coding: UTF-8 - * -

from string import maketrans   # maketrans function must be called.

intab = "aeiou"

outtab = "12345"

trantab = maketrans (intab, outtab)

str = "this is string example .... wow !!!"

print str.translate (trantab)

The above examples output results are as follows:
th3s 3s str3ng 2x1mpl2 .... w4w !!!

- C / C ++ language variable scope: local variables, global variables, file-level variables (Programming)
- Ubuntu file security removal tool (Linux)
- Ubuntu server 8.04 Firewall Guide (Linux)
- Docker build their own private warehouses (Linux)
- Linux host dual LAN transceiver package ARP problem (Linux)
- To install Git on Ubuntu systems (Server)
- Use Visual Studio Code Development TypeScript (Linux)
- Getting Started with Linux: Learn how to upgrade Docker in Ubuntu (Server)
- Use pg_basebackup build PostgreSQL streaming replication environment (Database)
- How to use Git to upload code to GitHub project (Linux)
- Nodejs command-line program development tutorial (Programming)
- Use HugePages optimize memory performance (Database)
- To install GCC development environment under SUSE11 (Linux)
- libreadline.so.6: can not open shared object file problem solution (Linux)
- MySQL function: group_concat () function (Database)
- Source install Python3.4 on CentOS (Linux)
- Ubuntu ADSL dial-up Internet access (Linux)
- Sublime Text 3 shortcuts summary (Linux)
- SELinux security permissions HTTP + PHP service changes (Server)
- Linux, modify the hostname (Linux)
  CopyRight 2002-2020 newfreesoft.com, All Rights Reserved.