Python Basics 2

Source: Internet
Author: User

Install Pycharm Professional Edition, do not Chinese

To write code that supports Linux and version 2.0 needs to be annotated at the beginning

#/usr/bin/env python

#-*-Coding:utf-8-*-

Operator

The result is a value

Arithmetic operations

A = 10*10

Assignment operations

A = A+1 is A+=1

The result is a Boolean value (return True or FALSE)

Comparison operation

A = 1>5

Logical operations

A = 1>6 or 1==1

Member operations

A = "Tom" in "L"

Basic data type (not all, supplemented later)

Digital

5 v= name.bit_length ()  int("1101",base=2 ) #把1101转换成2禁止  Base= + converts a to 16 binary print (v) # In Python3, int can represent all numbers, no matter how long, and after more than a few bits in the python2, they become long .

String

Name ="Alex"v=name.capitalize () #首字母变成大写print (v) name="Tom"v= Name.find ("T",) #查找alex中a所在的位置. Print (v) name="ALeA"v=name.casefold () #casefold all the letters into lowercase capitalize and all the letters to lowercase but the former more awesome print (v) #后者只能识别自己国家的前者可以识别所有name1="Tom"v1=Name1.upper () #upper all into uppercase print (v1) test="Tom"v= Test.center ( -,"in"The #center represents a fill of 20 for the total length of the representation that is around the word list can only be one character print (v) name="Tom"v= Name.count ("T",0,2) #去字符串中寻找子序列出现的次数0 2represents the print (v) name within the range="Tom"v= Name.endswith ("m") #以m结尾 return ture value v= Name.startswith ("T") #以t开头 translation ture value print (v) name="I am {name1},age{a}"v= Name.format (name1 ="Tom", a= at) #将name1, A is replaced with the specified value print (v) name="! 123tom"v=name.isalnum () #检查字符串中是否只包含数字 letters can also return a value of ture or Falseprint (v)
#name ="Tom"# if "T" inchName: If T executes in Name 1 does not execute the * print ("1")# Else: # Print ("2")# if "T"NotinchName: If T does not execute in Name 1 does not execute the * print ("1")# Else# Print ("2") # User="Tom"# pwd="123"# v= user=="Tom"and PWD = ="123"Or1==1and PWD = ="456"and1==2#等于Ture if trub# print (v) is established between and

Python Basics 2

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.