Python Forum
How do I put a variable inside a String in Python?
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I put a variable inside a String in Python?
#3
if python 3.6 or newer, use f-string:
>>> tmp = '12345'
>>> cmd3 = f"wmic process where processId = {tmp} get name | findstr /v Name"
>>> cmd3
'wmic process where processId = 12345 get name | findstr /v Name'
>>>
Reply


Messages In This Thread
RE: How do I put a variable inside a String in Python? - by Larz60+ - Sep-24-2018, 11:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  not able to call the variable inside the if/elif function mareeswaran 3 696 Feb-09-2025, 04:27 PM
Last Post: mareeswaran
  Variable being erased inside of if statement deusablutum 8 2,338 Jun-15-2024, 07:00 PM
Last Post: ndc85430
  Variable definitions inside loop / could be better? gugarciap 2 1,426 Jan-09-2024, 11:11 PM
Last Post: deanhystad
  How to create a variable only for use inside the scope of a while loop? Radical 10 9,047 Nov-07-2023, 09:49 AM
Last Post: buran
  Replacing String Variable with a new String Name kevv11 2 1,773 Jul-29-2023, 12:03 PM
Last Post: snippsat
  Need help on how to include single quotes on data of variable string hani_hms 5 7,761 Jan-10-2023, 11:26 AM
Last Post: codinglearner
  python r string for variable mg24 3 7,299 Oct-28-2022, 04:19 AM
Last Post: deanhystad
  USE string data as a variable NAME rokorps 1 1,590 Sep-30-2022, 01:08 PM
Last Post: deanhystad
  Removing Space between variable and string in Python coder_sw99 6 11,056 Aug-23-2022, 01:15 PM
Last Post: louries
  Remove a space between a string and variable in print sie 5 3,043 Jul-27-2022, 02:36 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020