| | |
noob question about strings
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
I want to create a string like this:
(just theoretically:-))
but I want string2 to show up formatted like this:
Random Number is
But, for the life of me I cant figure out how to create a new line and a tab, without writing string2 like this
I spent 30 minutes in the documentation and on google, and all i found was "\t" and "\n", but I cant even figure out how to make them work! Any help would be greatly appreciated, Thanks!
(just theoretically:-))
Python Syntax (Toggle Plain Text)
import random list1 = ["1", "2", "3"] string1 = random.choice(list1) string2 = "Random Number is" + string1
but I want string2 to show up formatted like this:
Random Number is
2
But, for the life of me I cant figure out how to create a new line and a tab, without writing string2 like this
Python Syntax (Toggle Plain Text)
"""Random Number is 2"""
I spent 30 minutes in the documentation and on google, and all i found was "\t" and "\n", but I cant even figure out how to make them work! Any help would be greatly appreciated, Thanks!
1
#2 Oct 29th, 2009
try
Also, you can read this
python Syntax (Toggle Plain Text)
string2 = "Random Number is\n{value:^16}".format(value = string1)
Last edited by Gribouillis; Oct 29th, 2009 at 12:59 am.
•
•
Join Date: Oct 2009
Posts: 2
Reputation:
Solved Threads: 0
0
#3 Oct 29th, 2009
thank you!
so the \n has to be in quotes.
I suppose I could eve do it like this:
but that other formatting stuff is really going to come in handy!
so the \n has to be in quotes.
I suppose I could eve do it like this:
Python Syntax (Toggle Plain Text)
string2 = "Random Number is" + "\n\t" + string1
0
#4 34 Days Ago
The other option is ...
... this makes the output more visual in your code.
python Syntax (Toggle Plain Text)
import random list1 = ["1", "2", "3"] string1 = random.choice(list1) string2 = """\ Random Number is %s""" % string1 print(string2)
May 'the Google' be with you!
![]() |
Similar Threads
- WinAPI noob question (C++)
- C++ Strings (C++)
- Noob with a question (IT Professionals' Lounge)
- Question (Networking Hardware Configuration)
- noob question (C)
- Noob question about Defining and Declaring. (C++)
- C++ handling of strings in a boolean expression (C++)
- NOOB question , graphical tiles (C++)
Other Threads in the Python Forum
- Previous Thread: Getting the connected user's ip in python
- Next Thread: pygame - filling in a block on a grid
| Thread Tools | Search this Thread |
address aliased anydbm bash beginner bits calling casino changecolor class clear conversion convert corners count cturtle cursor curves definedlines dictionary digital dynamic dynamically events examples excel external file float format frange function gui handling hints homework i/o iframe import info input java line linux list lists loan loop matching mouse multiple number numbers output parsing path port prime programming projects py py2exe pygame python random rational raw_input recursion recursive scrolledtext searchingfile shebang signal singleton string strings subprocess table tails terminal text thread threading time tkinter tlapse tooltip tuple tutorial type ubuntu unicode urllib urllib2 valueerror variable web-scrape whileloop word wxpython






