Python the third day

Source: Internet
Author: User
Tags logical operators

Yesterday's content review

Formatted output:%s%d%r

The first type:

'%s,%s ' (content 1, content 2)

The second type:

DIC = {' name ': ' Old boy ', ' age ': '% ' (name) s,% (ages) s '% dic

Denotes pure% with percent of

While else:

If the Wuile loop is interrupted by a break, do not go to the ELSE program

logical operators

And Or not

1. () >not > and >or, same priority, calculated from left to right

2. x or Y, X is True, return x and opposite

  

  

list:[' name ', true,[] ..., data of various data types, large amount of data, easy to operate

  

Tuple tuples. () read-only list.

dict:{' name ': ' Old boy ',
' Name_list ': [' negative ',.....]
' Alex ': {' age ': 40,
' Hobby ': ' Old_women ',
}
},
Store large amounts of data, relational data.

set:{' Wusir ', ' Alex ', ...}

numeric int:

Bit_length () The minimum number of digits to use when the decimal is in binary notation

Ps:a = Xvgshajasdas

s = A.bit_lengtuh ()

boolean bool:

There are two types of Boolean values: True, False. Is whether the reaction condition is correct or not

True 1 True

False 0 False

# The index of the string: The index is subscript, that is, the elements of the string starting from the first, the initial index is 0 and so on.
#
# a = ' Abcdefghijk '
# print (A[6])
# print (A[7])

# slices of a string: A slice is a segment of a string that is truncated by index (index: Index: STRIDE), \
# form a new string (the principle is that Gu head ignores butt).

# print (A[:5])
# print (A[3:7])

# The step of the string
#
# print (A[2:8:3])

#
# Common methods for strings
# a = ' Taidiganritian '
# a1= A.capitalize ()
# print (A1)
# **capitalize First letter uppercase, remaining letter lowercase

# a1 = A.center (20, ' * ')
# print (A1)
# *center Center brackets represent space and both sides of the symbol

# a1 = A.upper ()
# a2 = A.lower ()
# print (A1)
# print (A2)
# * * * * * Upper all become uppercase lower all become lowercase

# PS:
# code = ' Ritian '. Upper ()
# Your_code = input (' Please enter a verification code, not case sensitive '). Upper ()
# if Your_code = = Code:
# print (' ok! ')

# a = ' Taidiganritian '
# a1 = A.startswith (' t ')
# a2 = A.startswith (' d ', 3,6)
# print (A1)
# print (A2)
# * * * * startswith: Judge what content starts with,
# # returns BOOL, can slice, slice separated by commas.
# # ***endswith


# a1 = A.swapcase ()
# print (A1)
# *swapcase indicates case reversal

# a = ' Tai Digan3ri6tian '
# a1 = A.title ()
# print (A1)
# *title The first letter of each word not separated by letters

#
# a = ' Taidiganritian '
# a1 = A.find (' i ')
# print (A1)
# a2 = a.find (' i ', 5)
# print (A2)
# a3 = A.find (' I ')
# print (A3)
# a4 = A.index (' I ')
# print (A4)
# ***find: Index is found by element, can be sliced, cannot find return-1
# Index: Indexed by element, can be sliced, no error found


# a = '/taidi/n '
# a1 = A.strip ()
# print (A1)
# a = ' Dsahkjd Ndja '
# a1 = A.strip ()
# print (A1)
# ***strip Remove the front and back spaces, line breaks, tab characters.

# PS:
# username = input (' Please your name '). Strip ()
# if Username = = ' Taidi ':
# print (' OK ')
#

# #
# a = ' Taidi gan ritian '
# a1 = A.split ()
# print (A1)
# s = ' Taidi,gan,ritian '
# S1 = S.split (', ')
# print (S1)
# q = ' Taidiqganqritian '
# q1 = q.split (' q ')
# Print (Q1)
# ***split is separated by a space by default, if it is separated by another, it is written in parentheses, as above. Str-->list


# a = ' Taidi '
# a1 = ' + '. Join (a)
# print (A1)
#
# s = ' Dataidi '
# s1 = ' * '. Join (s)
# print (S1)
#
# q = [' Taidi ', ' gan ', ' Ritian ')
# q1 = '. Join (q)
# Print (Q1,type (Q1))
# ***join In some cases list--"str, for example the third kind of q


# a = ' little Teddy Taidi Little Teddy '
# a1 = A.replace (' Little Teddy ', ' Old Teddy ')
# print (A1)
# a2 = A.replace (' Little Teddy ', ' Old Teddy ', 2)
# print (A2)
# *replace in parentheses the latter replaces the former


# a = ' Hjiasgdyuasdhasguydwaukgdaskdjga '
# Public methods
# len (a)
# print (len (a)) Len is the count of all the numbers in the secondary string
# a1 =a.count (' d ')
# print (A1)
# *count calculates the number of occurrences of some elements, which can be sliced.
#
# Format formatted output
# Three different ways
# 1.
# msg = ' My name {}, this year {}, hobby {} '. Format (' Depths ', ' ", ' Wan ')
# Print (msg)
# 2.
# msg = ' My Name is{0},old{1},hobby{2},mynameagain{0} '. Format (' Junjie ', ' + ', ' play ')
# Print (msg)

# 3.
# msg = ' My Name Is{name},age{age},hobby{hobby} '. Format (name = ' Junjie ', age = ' all ', hobby = ' play ')
# Print (msg)

# a = ' Bchjadhjdasddagj '
# count = 0
# while Count<len (a):
# print (A[count])
# count = Count + 1
# for I in A:
# Print (i+ ' Taidi ')

#
# s = ' Alex '
#
# count = 0
# while Count < Len (s):
# print (S[count])
# count + = 1
# for I in S:
# Print (i+ ' SB ')

Python the third day

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.