Python Saturday study record 20171118 Day record one

Source: Internet
Author: User
Tags ord

Study Notes

1. Generate a large string of 1 to 50 with a space between each number

result = ' ' Store results

For I in Range (1,50,1): #遍历1-to 50 data

if i = =: #为了结尾出现空格这样处理

result = result + str (i) #把结果存放到变量中去

result = result + str (i) + "" #拼接成功

Print result

============


2, using while statistics of the sentence there are several numbers, dynamic input

Content = raw_input ("Please input a sentenece:\n") #输入

result = 0 #定义结果存放

index = 0 #定义索引

While index <= len (content)-1: #判断长度

If Content[index] in "0123456789": #判断是否在数字里面

Result + = 1 #如果在就加一存放结果

Index + = 1 #下标往移动

Print result #打印结果

==================

Third, the reverse of a list element exists in a new list


A = [1,3,4,5,6]


b = [] #保存结果


For I in a: #循环输出a


B.insert (0,i) #始终从第一个插入数据


Print B


========================

Enter four number flashback sort: and sort

Number = 0

b = []

c = []

For I in range (4):

Number = Int (raw_input ("Please enter hour\n"))

B.insert (0,number) #往第一个里面增加倒叙

C.append (number) #往数组里面增加,

C.sort () #调用函数进行排序

Print B

Print C


==========

Output 26 lowercase letters

result = []

For I in range (97,97 + 26):

Result + CHR (i)


Print result

Output Capital letters:

result = []

For I in range (65,65 + 26):

Result + CHR (i)


Print result


Uppercase and lowercase letters output together

result = ' #保存结果

For I in range (65,65 +): #从65到26为大写

Result + CHR (i) + CHR (i + +) #从97倒128小写

Print result

==============

Determine how many letters are included in a sentence

Content = raw_input (' Please input a sentence\n ')

Letter_count = 0

For s in content:

If s not in ' 0123456789 ':

Letter_count + = 1

Print Letter_count

=====================

Import string

sentence = raw_input ("Input youtsentence\n") # Storage location

letter_nbr=0 # counter

For i in sentence:

if I instring.letters # built-in functions

Letter_nbr+=1 # Count

Print LETTER_NBR

==========================

Encryption:

Letters = raw_input ("Please input some letter to encode:")

Encode_letters = ""

For s in letters:

if (S >= "a" and S < "W") or (S >= "a" and S <= "W"):

Encode_letters + = Chr (ord (s) + 4)

elif s >= "W" and S <= "Z":

Encode_letters + = Chr (ord (s)-Ord ("W") + 97)

elif s >= "W" and S <= "Z":

Encode_letters + = Chr (ord (s)-Ord ("W") + 65)

Else

Print "Some content is not letter! Please try agan! "

Continue


Print Encode_letters

=========

Judging character types


>>> a = ' dd '

>>> isinstance (A,int)

False

>>> isinstance (a,list)

False

>>> isinstance (A,STR)

True

>>> B = [' 1w ', 3, ' de ', 233]

>>> isinstance (b,list)

True

>>> isinstance (b,tuple)

False

>>> isinstance (b,dict)

False

>>> A = 1

>>> B = 0

>>> BOOL (1)

True

>>> BOOL (b)

False

>>>


Python Saturday study record 20171118 Day record one

Related Article

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.