

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get the size of a string in Python?
Python has a method called len() that gives us the length of any composite object. To get the length of a string, just pass the string to the len() call.
example
print(len('Hello World!'))
Output
12
If you want the size of the string in bytes, you can use the getsizeof() method from the sys module.
example
from sys import getsizeof getsizeof('Hello World!')
Output
33
You can read more about it at sys.getsizeof()
- Related Questions & Answers
- How to get the size of a list in Python?
- Python program to get all permutations of size r of a string
- How do we get the size of a list in Python?
- How to get the length of a string in Python?
- How do we get size of a list in Python?
- How to get the size of the tables of a MySQL database?
- How to get the Tab Size of a JTextArea in Java?
- How to get the size of a json object in JavaScript?
- How to get the size of a column of a table using JDBC?
- Split String of Size N in Python
- How to get first 100 characters of the string in Python?
- Python program to get all subsets of a given size of a set
- Python program to get all subsets of given size of a set
- Get the storage size of a database in MongoDB?
- How to get the screen size in Tkinter?
Advertisements