If the first character is an integer, it will not capitalize the first letter.
>>> '2s'.capitalize() '2s'
If you want the functionality, strip off the digits, you can use '2'.isdigit()
to check for each character.
>>> s = '123sa' >>> for i, c in enumerate(s): ... if not c.isdigit(): ... break ... >>> s[:i] + s[i:].capitalize() '123Sa'
Related Posts:
- How do I lowercase a string in Python?
- Difference between del, remove, and pop on lists
- How to use the pass statement
- How do you round UP a number?
- How do I update\upgrade pip itself from inside my virtual environment?
- ImportError: DLL load failed: The specified module could not be found
- Replacements for switch statement in Python?
- Correct way to write line to file?
- How to read a file line-by-line into a list?
- How do I sort a dictionary by value?
- ImportError: No module named pandas
- IndexError: too many indices for array
- TypeError: cannot unpack non-iterable NoneType object
- Where does pip install its packages?
- Python inline if statement
- if/else in a list comprehension
- data type not understood
- How to read a text file into a string variable and strip newlines?
- What does hash do in python?
- How to copy a dictionary and only edit the copy
- Creating a static class with no instances
- How to avoid “RuntimeError: dictionary changed size during iteration” error?
- if/else in a list comprehension
- Could not find a version that satisfies the requirement tensorflow
- Creating an empty Pandas DataFrame, then filling it?
- Finding the average of a list
- How to solve dictionary changed size during iteration error?
- iloc giving ‘IndexError: single positional indexer is out-of-bounds’
- Pandas, merging two dataframes on multiple columns, and multiplying result
- Are dictionaries ordered in Python 3.6+?
- How to customize a scatter matrix to see all titles?
- What is the problem with shadowing names defined in outer scopes?
- TypeError: write() argument must be str, not bytes (Python 3 vs Python 2 )
- How to clear the interpreter console?
- How to make a class JSON serializable
- What does the ‘b’ character do in front of a string literal?
- How can I upgrade NumPy?
- How to get element-wise matrix multiplication (Hadamard product) in numpy?
- Matplotlib automatic legend outside plot
- Why am I getting this syntax error: keyword can’t be an expression
- Forbidden (403) CSRF verification failed. Request aborted. Even using the {% csrf_token %}
- Flask ImportError: No Module Named Flask
- ModuleNotFoundError: No module named ‘MySQLdb’
- How to change dataframe column names in pyspark?
- Normalize data in pandas
- Can’t broadcast input array from shape (3,1) into shape (3,)
- Unresolved reference issue in PyCharm
- How to use 2to3 properly for python?
- Is there a way to return literally nothing in python?
- Is there a built-in function to print all the current properties and values of an object?
- How to troubleshoot an “AttributeError: __exit__” in multiproccesing in Python?
- TypeError : Unhashable type
- Read PDF in Python and convert to text in PDF
- Importing variables from another file in Python
- How to read a file without newlines?
- Encrypt & Decrypt using PyCrypto AES 256
- Multiple try codes in one block
- Error: Segmentation fault (core dumped)
- can’t open tensorboard 0.0.0.0:6006 or localhost:6006
- ImportError: No module named six
- Easy pretty printing of floats?
- How to fix “Can’t find a default Python” error
- TypeError: ‘newline’ is an invalid keyword argument for this function
- datetime to string with series in pandas
- Is it possible only to declare a variable without assigning any value in Python?
- How to Install pip for python 3.7 on Ubuntu 18?
- How to add a new row to an empty numpy array
- Logical indexing with lists
- How to set timeout on python’s socket recv method?
- How does str(list) work?
- Automatic indentation for Python in Notepad++
- pandas groupby sort within groups
- Python Socket Receive Large Amount of Data
- How to make a python script wait for a pressed key?
- TypeError: Image data can not convert to float
- Mean Squared Error in Numpy?
- Turn a single number into single digits Python
- Is there a head and tail method for Numpy array?
- What should I use to open a url instead of urlopen in urllib3
- How to find out whether a file is at its `eof`?
- TypeError: Image data can not convert to float
- coercing to Unicode: need string or buffer, NoneType found when rendering in django admin
- Convert from ASCII string encoded in Hex to plain ASCII?
- Simple way to create matrix of random numbers
- pandas: multiple conditions while indexing data frame – unexpected behavior
- Create a list with initial capacity in Python
- Accessing dict_keys element by index in Python3
- How to update Pandas from Anaconda and is it possible to use eclipse with this last
- Does python support character type?
- Styling multi-line conditions in ‘if’ statements?
- What is related_name used for?
- Symbol not found: __PyCodecInfo_GetIncrementalDecoder
- How can I tail a log file in Python?
- How to write unicode strings into a file?
- python-How to set global variables in Flask?
- How do I install pip on macOS or OS X?
- NameError: name ‘get_ipython’ is not defined
- Equivalent to matlab’s imagesc in matplotlib? [duplicate]
- bash: syntax error near unexpected token `(‘ – Python
- Find all files in a directory with extension .txt in Python