Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print part of a variable
#1
Hm, I want to print only 27 + a random generated number so it should be (for example) 2717. The content of variable meters should not be included, not sure how to do it.

lenght = meters + ", 27" + str(random.randint(0,50))
Reply
#2
By removing meters from the statement.
Reply
#3
Variable lenght is passed on to a function where meters is needed, in the function I will print variable lenght but without meters.
Reply
#4
The answer remains same. meters and length are two different variables.
If function needs meters also, pass it as an additional argument.
Reply
#5
Ok, thanks. Will test.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling functions by making part of their name with variable crouzilles 4 803 Nov-02-2023, 12:25 PM
Last Post: noisefloor
  Print variable without '' and spaces arnonim 1 721 Jan-30-2023, 05:23 PM
Last Post: deanhystad
  Problem with print variable in print.cell (fpdf) muconi 0 653 Dec-25-2022, 02:24 PM
Last Post: muconi
  Remove a space between a string and variable in print sie 5 1,758 Jul-27-2022, 02:36 PM
Last Post: deanhystad
  How to write a part of powershell command as a variable? ilknurg 2 1,114 Jul-26-2022, 11:31 AM
Last Post: ilknurg
  Can you print a string variable to printer hammer 2 1,928 Apr-30-2022, 11:48 PM
Last Post: hammer
  Print variable between " paulo79 5 1,688 Mar-11-2022, 05:16 PM
Last Post: deanhystad
  How to include input as part of variable name Mark17 4 2,486 Oct-01-2021, 06:45 PM
Last Post: Mark17
  How to use a variable in Python (2.x) to define decimal part? MDRI 4 2,316 May-07-2021, 12:39 AM
Last Post: MDRI
  When I print a key from dict it prints it but when I try to assign it to a variable I stefanvelikov 3 2,347 Nov-27-2020, 01:29 PM
Last Post: stefanvelikov

Forum Jump:

User Panel Messages

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