1, reverse a string of strings output, such as "ABCD" into "DCBA"
str1= "ABCD" Print Str1[::-1]
2, judge whether it is a palindrome--to determine whether the user input string is a palindrome. Palindrome refers to both positive and negative spellings are the same words, such as "racecar".
while (1): input_str = raw_input (' Please input your string: ') if input_str== "quit": print "Bye" break elif input_str==input_str[::-1]: print "Your input is Huiwen" else: print "Your input was not Huiwen"
3. Count the number of letters in an English sentence:
# ! Coding=utf-8txt="Failure is probably the fortification in your pole"count= {} for in txt: count.setdefault (i,0)# If the dictionary does not have key I, The key is added, and the value of the key is set to 0. If you already have this key, do not change the dictionary count[i]=count[i]+1Print count
4. Count the number of words in an English sentence:
#! Coding=utf-8txt= "Failure are probably the fortification in your pole are" strlist=txt.split ("") countword={}for I in Strlist: Countword.setdefault (i,0) countword[i]=countword[i]+1print Countword
(python) Programming Little Practice