Integer String Boolean operation python

Integer and Boolean values

There python2 int, long (long integer).

python3 only int.

The long string of numbers meaning that when L is relatively long back display.

num = 15     。              bit_length:位的长度的意思
print(num.bit_length()) 结果:4     十进制转二进制占用位数

Results beginning 0b turn decimal binary output binary display means.

print(int(0b100101)) 结果:37

Only numbers 0 is False, others are True.

String as long as the content is True, no content is False.

print (str (True)) Returns a string.

print (int (True)) returns 1.

print (int (False)) returns 0.

Detailed strings

1. Index

The default start from zero.

Not out of range error.

2. Slice

Slice out of range on the error.

3. step

A walk, go left or go right, left is 0, the right is at -1.

4. palindrome

The positive output and the output is the same counter-example: Shanghai water from the sea

while True:
    num = input("请输入回文")
    if num == num[::-1]:
        print("是回文")
        break
    else:
        print("不是回文")

Detailed string method

.replice (1,2) the old value, new value replacing means

.split () divided by default spaces, line breaks, tabs are cut, you can also specify their own in parentheses. split ( "+", maxsplit) maxsplit = 1 + sign is already divides, 1 meaning.

.strip () Default removing head and tail ends of the spaces, line breaks, tabs. You can also fill out their own letter head and tail ends of the brackets were removed, the other position does not work.

.upper all caps

.lower all lowercase

# s = "XbGj"
# msg = input("请输入验证码(XbGj):")
# if msg.upper() == s.upper():
#     print("成功!")
# else:
#     print("失败")
import random  # 随机数
# ascii
# 48 - 57 数字
# 65 - 90 大写
# 97 - 122 小写
# print(chr(97)) # 通过十进制查找编码上对应的字符
# 自动生成验证码:
# s = f"{chr(random.randint(48,57))}{chr(random.randint(65,90))}{chr(random.randint(97,122))}{chr(random.randint(48,57))}" 
# 4位
# msg = input(f"请输入验证码{s}:")
# if msg.lower() == s.lower():
#     print("验证成功!")
# else:
#     print("验证失败")
# 重点:    
# str.strip()  默认去除头尾空格,换行符,制表符,也可以自己写
# str.split()  分割,默认以空格,换行符,制表符,也可以自己写 
# str.replace() 替换,旧值替换成新值。   
# str.upper()  全部大写 
# str.lower()  全部小写
# str.startswith()  # s[0] 已什么开头   
# str.endswith()    # s[-1] 已什么结尾  
# str.count() 统计
# is 系列:    
# str.isalpha() 判断是不是由字母,中文组成 -- 返回的是布尔值
# str.isdigit()  判断是否是数字 -- bug  
# str.isdecimal() 判断是否是十进制数   
# str.isalnum()  判断是不是字母,数字,汉字

Guess you like

Origin www.cnblogs.com/biyunfeng/p/11934564.html