There are two functions that give an object’s string representation, repr()
and str()
. The former is designed to convert the object to as-code string, while the latter gives user-friendly string.
When you input the variable name in the command line, repr()
is used, and \n
character is shown as \n
(as-code). When you use print
, str()
is used, and \n
is shown as a new line (user-friendly).
By the way, str
is a bad name for a variable, as it’s the same as the built-in.
Related Posts:
- Convert bytes to a string
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- Python Variable Declaration
- How do I compare two strings in python?
- Pip freeze vs. pip list
- Best way to convert string to bytes in Python 3?
- Best way to convert string to bytes in Python 3?
- TypeError: not all arguments converted during string formatting python
- WinError 2 The system cannot find the file specified (Python)
- Could not find a version that satisfies the requirement tensorflow
- Convert bytes to a string
- How to print like printf in Python3?
- Could not find a version that satisfies the requirement tensorflow
- Local variable referenced before assignment?
- How to remove punctuation in python?
- pip or pip3 to install packages for Python 3?
- TypeError: write() argument must be str, not bytes (Python 3 vs Python 2 )
- Python: TypeError: cannot concatenate ‘str’ and ‘int’ objects
- Check string “None” or “not” in Python 2.7
- Change figure size and figure format in matplotlib
- How can I concatenate str and int objects?
- How to get the filename without the extension from a path in Python?
- sprintf like functionality in Python
- n-grams in python, four, five, six grams?
- Alphabet range in Python
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- ValueError: unsupported pickle protocol: 3, python2 pickle can not load the file dumped by python 3 pickle?
- How do I format a string using a dictionary in python-3.x?
- Type error Unhashable type:set
- Replacing a character from a certain index
- How to convert ‘binary string’ to normal string in Python3?
- TypeError: ‘_io.TextIOWrapper’ object is not subscriptable
- Properly formatted multiplication table
- Why is parenthesis in print voluntary in Python 2.7?
- How to read the last line of a file in Python?
- How to compare individual characters in two strings in Python 3
- How can I copy a Python string?
- Split string using a newline delimiter with Python
- What is the meaning of “int(a[::-1])” in Python?
- dump() missing 1 required positional argument: ‘fp’ in python json
- Python cant convert ‘list’ object to str error [closed]
- Using strip() to clean up a string
- Does python have header files like C/C++?
- Python – difference between two strings
- How to use filter, map, and reduce in Python 3
- not all arguments converted during string formatting.. NO % variables
- sklearn error ValueError: Input contains NaN, infinity or a value too large for dtype(‘float64’)
- Updating a dictionary in python
- TypeError: cannot perform reduce with flexible type
- Python convert tuple to string
- ImportError: numpy.core.multiarray failed to import
- NameError: global name ‘xrange’ is not defined in Python 3
- What does “SyntaxError: Missing parentheses in call to ‘print'” mean in Python?
- How to remove \xa0 from string in Python?
- How to check if the string is empty?
- What is __pycache__?
- How to install pip3 on Windows?
- What is the purpose of “pip install –user …”?
- “[ ]” vs. “[[ ]]” in Bash shell
- Add list to set?
- Infinite integer in Python
- Quoting backslashes in Python string literals
- Python string class like StringBuilder in C#?
- C – The %x format specifier
- How to have an array of arrays in Python
- Detect whether a Python string is a number or a letter
- How do I append one string to another in Python?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- Python: can’t assign to literal
- “Initializing” variables in python?
- Difference between except: and except Exception as e:
- “Unicode Error “unicodeescape” codec can’t decode bytes… Cannot open text files in Python 3
- How to downgrade python from 3.7 to 3.6
- Loading a file with more than one line of JSON into Pandas
- bash : Bad Substitution
- How can I find the first occurrence of a sub-string in a python string?
- Using Look Up Tables in Python
- How to assign multiple lines string in Powershell Console
- LC-3 STR with R1 as offset
- Django Rest Framework — no module named rest_framework
- Unsupported operation :not writeable python
- Convert a Unicode string to a string in Python (containing extra symbols)python string unicode type-conversion
- Object of type ‘map’ has no len() in Python 3
- how to exit a python script in an if statement
- AttributeError: ‘str’ object has no attribute ‘items’
- Not able to pip install pickle in python 3.6
- ImportError: cannot import name NUMPY_MKL
- Python: Pandas pd.read_excel giving ImportError: Install xlrd >= 0.9.0 for Excel support
- How to strip a specific word from a string?
- Printing subscript in python
- How to clear Tkinter Canvas?
- TypeError: ‘range’ object does not support item assignment
- Convert string to variable name in python
- How to install pip for Python 3 on Mac OS X?
- Installing scipy for python 2.7
- Generate a random letter in Python
- ‘module’ has no attribute ‘urlencode’
- Cannot concatenate ‘str’ and ‘float’ objects?
- How to repeat individual characters in strings in Python
- How to install PyQt4 on Windows using pip?