Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
.to_bytes() in Python
Next article icon

codecs.encode() in Python

Last Updated : 26 Mar, 2020
Comments
Improve
Suggest changes
Like Article
Like
Report

With the help of codecs.encode() method, we can encode the string into the binary form .

Syntax : codecs.encode(string)

Return : Return the encoded string.

Example #1 :
In this example we can see that by using codecs.encode() method, we are able to get the encoded string which can be in binary form by using this method.




# import codecs
import codecs
  
s = 'GeeksForGeeks'
# Using codecs.encode() method
gfg = codecs.encode(s)
  
print(gfg)
 
 

Output :

b’GeeksForGeeks’

Example #2 :




# import codecs
import codecs
  
s = 'I love python.'
# Using codecs.encode() method
gfg = codecs.encode(s)
  
print(gfg)
 
 

Output :

b’I love python.’



Next Article
.to_bytes() in Python

J

Jitender_1998
Improve
Article Tags :
  • Python
  • Python Programs
  • Python codecs-module
Practice Tags :
  • python

Similar Reads

  • Detect Encoding of CSV File in Python
    When working with CSV (Comma Separated Values) files in Python, it is crucial to handle different character encodings appropriately. Encoding determines how characters are represented in binary format, and mismatched encodings can lead to data corruption or misinterpretation. In this article, we wil
    3 min read
  • Python | Encoding Decoding using Matrix
    This article is about how we use the matrix to encode and decode a text message and simple strings. Encoding process : Take a String convert to corresponding number shown below convert to 2D matrix(array). Now we have 2x2 matrix! When we multiply this matrix with encoding matrix we get encoded 2x2 m
    4 min read
  • .to_bytes() in Python
    In Python, the .to_bytes() method is used to convert an integer into its byte representation. This is useful when weneed to store or transmit data in binary format. Example: Convert the integer 10 into bytes[GFGTABS] Python num = 10 byte_data = num.to_bytes(2, 'big') print(byte_data) [/GFGTA
    2 min read
  • Interesting Facts About Python
    Python is a high-level, general-purpose programming language that is widely used for web development, data analysis, artificial intelligence and more. It was created by Guido van Rossum and first released in 1991. Python's primary focus is on simplicity and readability, making it one of the most acc
    7 min read
  • Add Comma Between Numbers - Python
    When working with large numbers in Python, adding commas for better readability can make them easier to understand. In this article, we’ll explore simple ways to add commas between numbers, helping make large numbers more readable and neatly formatted. Using format() format() function in Python prov
    3 min read
  • hashlib.blake2s() in Python
    With the help of hashlib.blake2s() method, we can convert the normal string in byte format is converted to an encrypted form. Passwords and important files can be converted into hash to protect them with the help of hashlib.blake2s() method. Syntax : hashlib.blake2s() Return : Return the hash code f
    1 min read
  • Convert Bytes To Json using Python
    When dealing with complex byte data in Python, converting it to JSON format is a common task. In this article, we will explore different approaches, each demonstrating how to handle complex byte input and showcasing the resulting JSON output. Convert Bytes To JSON in PythonBelow are some of the ways
    2 min read
  • How to copy a string in Python
    Creating a copy of a string is useful when we need a duplicate of a string to work with while keeping the original string intact, strings in Python are immutable which means they can't be altered after creation, so creating a copy sometimes becomes a necessity for specific use cases. Using SlicingSl
    2 min read
  • Python - Golomb Encoding for b=2n and b!=2n
    The Golomb coding is a form of parameterized coding in which integers to be coded are stored as values relative to a constant b Coding:- A positive number x is spoken to in two sections: The initial segment is an unary portrayal of q+1, where q is the remainder floor((x/b)), andThe subsequent part i
    3 min read
  • How to Print a Tab in Python
    In Python, printing a tab space is useful when we need to format text, making it more readable or aligned. For example, when displaying data in columns, we might want to add a tab space between the values for a cleaner appearance. We can do this using simple methods like \t, the print() function or
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences