About 264,000 results
Open links in new tab
  1. How can I copy a Python string? - Stack Overflow

    You don't need to copy a Python string. They are immutable, and the copy module always returns the original in such cases, as do str() , the whole string slice, and concatenating with an empty string.

  2. How to copy a string in Python - GeeksforGeeks

    Dec 2, 2024 · In Python, removing a substring from a string can be achieved through various methods such as using replace() function, slicing, or regular expressions. Depending on your specific use case, you may want to remove all instances of a substring or just the first occurrence.

  3. Is it possible to copy string in Python? [SOLVED] - GoLinuxCloud

    Jan 9, 2024 · Here are different methods to copy a string in Python: Assignment Operator (=): Simply assigns the value of one variable to another. This creates a new reference to the same string object in memory. Slicing ([:]): Creates a new string by slicing the entire original string. This effectively produces a copy of the original string.

  4. How to Copy String in Python - Delft Stack

    Feb 2, 2024 · In summary, this tutorial explored different methods to copy a string in Python, considering the immutability of strings. We discussed techniques such as concatenation, string slicing, the str() function, and string formatting using % and format() .

  5. Python String Copy - Spark By Examples

    May 20, 2024 · You can copy the string in Python using many ways, for example, by using + operators, slicing, str(), string formatting, for loop, and = assignment operator. In this article, I will explain how to copy a string by using all these functions with examples. 1. Quick Examples of Copying a String

  6. How to copy string in python - CodeVsColor

    Sep 1, 2021 · Since string is immutable, we can get a new copy of the string by adding an empty string to the original string. Also, we can slice the whole string or use str() function to get a copy of a string. Let’s try each of these methods:

  7. Copy Module – Python | GeeksforGeeks

    Mar 12, 2025 · To use the copy module, you have toi first import it in your Python script by the following command: import copy. Syntax and Functions 1. copy.copy(obj) (Shallow Copy) Syntax: copy.copy(obj) Parameters: obj: object to be copied. Returns: shallow copy of obj, where only the outer object is duplicated, while nested objects remain referenced.

  8. Python — How To Copy String - Medium

    Jan 26, 2022 · We need to add an empty string to the original string using the concatenation operator while declaring the new string. The following code uses an empty string to get a copy string in Python.

  9. Python Copy String Function: A Comprehensive Guide

    Jan 23, 2025 · This blog post will dive deep into the concept of copying strings in Python, explore different methods, and discuss best practices. Table of Contents. Fundamental Concepts of String Copying in Python. Immutability of Strings; Why Copy Strings? Usage Methods of String Copying. Using Assignment Operator; Using the copy Module; Using Slicing ...

  10. Copy string - Python - Stack Overflow

    Apr 10, 2010 · For Windows, you use win32clipboard. You will need pywin32. For GTK (at least on GNU/Linux), you can use pygtk. EDIT: Since you mentioned (a bit late) you're using wxPython, they actually have a module for this too, wx.Clipboard. What if, the application was supposed to be multi-platform? Would it be possible?

Refresh