Oct-29-2019, 05:17 AM
There is str.startswith() method which:
Output:Return True if string starts with the prefix, otherwise return False. prefix can also be a tuple of prefixes to look for. With optional start, test string beginning at that position. With optional end, stop comparing string at that position.
So:>>> my_string = '1100' >>> my_string.startswith('1') True >>> my_string.startswith('0') FalseYou can see all the str methods by writing
str.
into interactive interpreter and pressing TAB two times:>>> str. str.capitalize( str.index( str.isspace( str.replace( str.strip( str.casefold( str.isalnum( str.istitle( str.rfind( str.swapcase( str.center( str.isalpha( str.isupper( str.rindex( str.title( str.count( str.isascii( str.join( str.rjust( str.translate( str.encode( str.isdecimal( str.ljust( str.rpartition( str.upper( str.endswith( str.isdigit( str.lower( str.rsplit( str.zfill( str.expandtabs( str.isidentifier( str.lstrip( str.rstrip( str.find( str.islower( str.maketrans( str.split( str.format( str.isnumeric( str.mro( str.splitlines( str.format_map( str.isprintable( str.partition( str.startswith(You can find what any of these methods do by using built-in help:
>>> help(str.capitalize) Help on method_descriptor: capitalize(self, /) Return a capitalized version of the string. More specifically, make the first character have upper case and the rest lower case.Press Q to exit help.
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.