In Python 2.x, you would do
isinstance(s, basestring)
basestring is the abstract superclass of str and unicode. It can be used to test whether an object is an instance of str or unicode.
In Python 3.x, the correct test is
isinstance(s, str)
The bytes class isn’t considered a string type in Python 3.
Related Posts:
- How can I print variable and string on same line in Python?
- How do I lowercase a string in Python?
- How do I get a substring of a string in Python?
- Does Python have a string ‘contains’ substring method?
- How to read a file line-by-line into a list?
- strip(char) on a string
- How to convert list to string [duplicate]
- TypeError: a bytes-like object is required, not ‘str’ when writing to a file in Python3
- Print string to text file
- Best way to convert string to bytes in Python 3?
- Pythonic way to create a long multi-line string
- Best way to convert string to bytes in Python 3?
- Does Python have a string ‘contains’ substring method?
- TypeError: not all arguments converted during string formatting python
- ‘str’ object does not support item assignment
- How do I append one string to another in Python?
- How do I append one string to another in Python?
- Random string generation with upper case letters and digits
- How can I split and parse a string in Python?
- What’s the canonical way to check for type in Python?
- What is the naming convention in Python for variable and function names?
- How to read a text file into a string variable and strip newlines?
- Convert bytes to a string
- TypeError: ‘float’ object is not callable
- How to print like printf in Python3?
- How to read a text file into a string variable and strip newlines?
- How do I check if a variable exists?
- Python convert tuple to string
- write() versus writelines() and concatenated strings
- Why is it string.join(list) instead of list.join(string)?
- Why is it string.join(list) instead of list.join(string)?
- Split a string into 2 in Python
- Best way to strip punctuation from a string
- Split string with multiple delimiters in Python [duplicate]
- How to check if the string is empty?
- How to find all occurrences of a substring?
- TypeError: ‘str’ object cannot be interpreted as an integer [duplicate]
- How do I convert a list of ascii values to a string in python?
- How to check whether a str(variable) is empty or not?
- Python TypeError: not enough arguments for format string
- What is dtype(‘O’), in pandas?
- What does the ‘b’ character do in front of a string literal?
- Append integer to beginning of list in Python
- How to add a string in a certain position?
- Check string “None” or “not” in Python 2.7
- Remove all special characters, punctuation and spaces from string
- This can be done without regex:
- How can I concatenate str and int objects?
- What is dtype(‘O’), in pandas?
- What does the ‘b’ character do in front of a string literal?
- Best way to replace multiple characters in a string?
- How to determine a Python variable’s type?
- Convert columns to string in Pandas
- Change column type in pandas
- How to delete a character from a string using Python
- Python: Get the first character of the first string in a list?
- Determine the type of an object?
- How to convert string to binary?
- Remove the first character of a string
- Convert hex to binary
- Quoting backslashes in Python string literals
- Python string class like StringBuilder in C#?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- Remove all special characters, punctuation and spaces from string
- How to check if a string is a substring of items in a list of strings?
- Best way to replace multiple characters in a string?
- How do I remove a substring from the end of a string?
- How can I splice a string?
- Detect whether a Python string is a number or a letter
- Finding all possible permutations of a given string in python
- How do I append one string to another in Python?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- Importing variables from another file?
- AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character
- ValueError: cannot index with vector containing NA / NaN values
- How to convert string to binary?
- Converting from a string to boolean in Python?
- How do I format a string using a dictionary in python-3.x?
- Removing numbers from string
- Count the number of occurrences of a character in a string
- How do I check if there are duplicates in a flat list?
- How to find char in string and get all the indexes?
- Append a tuple to a list – what’s the difference between two ways?
- Remove quotes from String in Python
- Convert hex string to int in Python
- How can I check if character in a string is a letter? (Python)
- How can I check if character in a string is a letter? (Python)
- How can I find the first occurrence of a sub-string in a python string?
- Viewing all defined variables
- How to concatenate items in a list to a single string?
- Printing variables in Python 3.4
- Replacing a character from a certain index
- AttributeError: ‘list’ object has no attribute ‘lower’ gensim
- Find the nth occurrence of substring in a string
- How to convert ‘binary string’ to normal string in Python3?
- Properly formatted multiplication table
- Copy a list of list by value and not reference
- How to get a function name as a string?
- Pandas error “Can only use .str accessor with string values”
- Python: Converting string into decimal number