What is \r in python? [duplicate] - python

This question already has answers here:
What is the difference between a "line feed" and a "carriage return"?
(4 answers)
What does "\r" do in the following script?
(4 answers)
Closed 2 years ago.
I am a newbie in the field of python. I recently came across \r (carriage return). It seems like it performs the same task as \n. Can anyone tell me the difference between \r and \n and specify the operation of \r?

Related

What is the Python ` symbol [duplicate]

This question already has answers here:
What do backticks mean to the Python interpreter? Example: `num`
(3 answers)
Meaning of the backtick character in Python
(2 answers)
Closed 1 year ago.
Lots of old python code I look in has this ` symbol around a lot of stuff, what does it do? Now it is not considered valid syntax, obviously.
And I don't think it is just another string identifier, its sometimes wrapped around functions in the code I'm looking at.
Any help will be appreciated.

Difference detween line.rstrip("\n") and line.rstrip(os.linesep)? [duplicate]

This question already has answers here:
How can I remove a trailing newline?
(27 answers)
What is os.linesep for?
(2 answers)
Closed 1 year ago.
Real quick question, what is the difference between line.strip("\n") and line.rstrip(os.linesep)? Especially, when using them in the Fasta file and other bioinformatics fields.
line.strip("\n") removes the new-line character for UNIX and UNIX-like OSs. On the other side, line.strip(os.linesep) would automatically change to the correct new-line character for your current operation system (Mac OS, Linux, Windows, etc)

What are these re.search meta characters doing? Where is my address? Not fully understanding syntax and RB [duplicate]

This question already has answers here:
Reference - What does this regex mean?
(1 answer)
What exactly is a "raw string regex" and how can you use it?
(7 answers)
Python3 regex on bytes variable [duplicate]
(2 answers)
Closed 2 years ago.
my_address = re.search(rb'\x80\xC9.{4}\x94\x12\x8A\x41\x08', bytes).start() + 5
Read the doc but I'm a bit confused.
My guess is
\x80\xC9\BYTE\BYTE\BYTE\BYTE\BYTE\x94\x12\x8A\x41\x08\BYTE\BYTE\BYTE\BYTE\BYTE\my_address\
Thanks

Why does regex [!##$%^&*()-_=+\|\[{\]};:\'<,.>/?~`]+ match digits? [duplicate]

This question already has answers here:
Error in regex to catch special characters
(2 answers)
Closed 6 years ago.
Can someone explain the following result?
Input to python 2.7.12 shell
re.match('[!##$%^&*()-_=+\|\[{\]};:\'<,.>/?~`]+', '2222').group()
Output:
'2222'
I don't understand why digits match this expression.
re.match('[!##$%^&*()-_=+\|\[{\]};:\'<,.>/?~`]+', '2222').group()
# ^^^
)-_ inside the brackets is a character range, and 2 is in that range.

How to print bold text in python with ```format```? [duplicate]

This question already has answers here:
How can I print bold text in Python?
(17 answers)
Closed 6 years ago.
I'm aware of the this solution and this solution when using string concatenator +. However I couldn't find how to do it with the new printing style (more details here), e.g. print '{:10s}'.format(str).
The same ANSI escape sequences work just fine.
print('\033[1m{:10s}\033[0m'.format('foo'))

Categories

Resources