Trying to do multiple tabs using t
I'm trying to print a certain string each time on a new line and each line adding a new tab.
For example:
String
String
String
The code I used:
print(string + "nt" + string "nt" + string)
Which gives the output:
String
String
String
Can someone explain me why is it happening, and what are the ways to work around it?
python string
add a comment |
I'm trying to print a certain string each time on a new line and each line adding a new tab.
For example:
String
String
String
The code I used:
print(string + "nt" + string "nt" + string)
Which gives the output:
String
String
String
Can someone explain me why is it happening, and what are the ways to work around it?
python string
3
I'm not sure why you expect your first result. You start a new line, and then have a single tab. If you want two tabs, you need to put two tabs.
– Daniel Roseman
Nov 23 '18 at 18:39
n jumps to a new line, but does o to the beginning of the line
– Tobias Wilfert
Nov 23 '18 at 18:39
add a comment |
I'm trying to print a certain string each time on a new line and each line adding a new tab.
For example:
String
String
String
The code I used:
print(string + "nt" + string "nt" + string)
Which gives the output:
String
String
String
Can someone explain me why is it happening, and what are the ways to work around it?
python string
I'm trying to print a certain string each time on a new line and each line adding a new tab.
For example:
String
String
String
The code I used:
print(string + "nt" + string "nt" + string)
Which gives the output:
String
String
String
Can someone explain me why is it happening, and what are the ways to work around it?
python string
python string
edited Nov 23 '18 at 18:49
Zoe
11.7k74479
11.7k74479
asked Nov 23 '18 at 18:38
DanielDaniel
31
31
3
I'm not sure why you expect your first result. You start a new line, and then have a single tab. If you want two tabs, you need to put two tabs.
– Daniel Roseman
Nov 23 '18 at 18:39
n jumps to a new line, but does o to the beginning of the line
– Tobias Wilfert
Nov 23 '18 at 18:39
add a comment |
3
I'm not sure why you expect your first result. You start a new line, and then have a single tab. If you want two tabs, you need to put two tabs.
– Daniel Roseman
Nov 23 '18 at 18:39
n jumps to a new line, but does o to the beginning of the line
– Tobias Wilfert
Nov 23 '18 at 18:39
3
3
I'm not sure why you expect your first result. You start a new line, and then have a single tab. If you want two tabs, you need to put two tabs.
– Daniel Roseman
Nov 23 '18 at 18:39
I'm not sure why you expect your first result. You start a new line, and then have a single tab. If you want two tabs, you need to put two tabs.
– Daniel Roseman
Nov 23 '18 at 18:39
n jumps to a new line, but does o to the beginning of the line
– Tobias Wilfert
Nov 23 '18 at 18:39
n jumps to a new line, but does o to the beginning of the line
– Tobias Wilfert
Nov 23 '18 at 18:39
add a comment |
3 Answers
3
active
oldest
votes
You can create a for
loop and add a tab in each cycle:
number = 3
string = "String"
for i in range(number):
print('t' * i + string + 'n', end="")
Output:
String
String
String
You can use it for any positive value of variable number
. You can also create a function that does the above:
def printTabbed(number,string):
for i in range(number):
print('t' * i + string + 'n', end="")
And then call it:
printTabbed(3,"String")
add a comment |
Use
print(string + "nt" + string "ntt" + string)
In your code, the third line only contains one tab
indent (indents don't "carry over" to the next lines, so you have to indent every line from the start).
1
Thanks for answer! So if I had to do something like printing a complex indented list I would have to use some kind a variable that would track the number of indentations I'm using?
– Daniel
Nov 23 '18 at 18:43
@Daniel Exactly. For every line you need to determine its indentation, and print exactly as manytabs
– andersource
Nov 23 '18 at 18:55
add a comment |
Considering you want to do this multiple times it is best to use a loop such as this:
n = 10 // amount of times you want to print
for x in range(n):
tabs = "t"*x
print(tabs+"String"+"n")
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451566%2ftrying-to-do-multiple-tabs-using-t%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can create a for
loop and add a tab in each cycle:
number = 3
string = "String"
for i in range(number):
print('t' * i + string + 'n', end="")
Output:
String
String
String
You can use it for any positive value of variable number
. You can also create a function that does the above:
def printTabbed(number,string):
for i in range(number):
print('t' * i + string + 'n', end="")
And then call it:
printTabbed(3,"String")
add a comment |
You can create a for
loop and add a tab in each cycle:
number = 3
string = "String"
for i in range(number):
print('t' * i + string + 'n', end="")
Output:
String
String
String
You can use it for any positive value of variable number
. You can also create a function that does the above:
def printTabbed(number,string):
for i in range(number):
print('t' * i + string + 'n', end="")
And then call it:
printTabbed(3,"String")
add a comment |
You can create a for
loop and add a tab in each cycle:
number = 3
string = "String"
for i in range(number):
print('t' * i + string + 'n', end="")
Output:
String
String
String
You can use it for any positive value of variable number
. You can also create a function that does the above:
def printTabbed(number,string):
for i in range(number):
print('t' * i + string + 'n', end="")
And then call it:
printTabbed(3,"String")
You can create a for
loop and add a tab in each cycle:
number = 3
string = "String"
for i in range(number):
print('t' * i + string + 'n', end="")
Output:
String
String
String
You can use it for any positive value of variable number
. You can also create a function that does the above:
def printTabbed(number,string):
for i in range(number):
print('t' * i + string + 'n', end="")
And then call it:
printTabbed(3,"String")
answered Nov 23 '18 at 18:44
Vasilis G.Vasilis G.
3,5332722
3,5332722
add a comment |
add a comment |
Use
print(string + "nt" + string "ntt" + string)
In your code, the third line only contains one tab
indent (indents don't "carry over" to the next lines, so you have to indent every line from the start).
1
Thanks for answer! So if I had to do something like printing a complex indented list I would have to use some kind a variable that would track the number of indentations I'm using?
– Daniel
Nov 23 '18 at 18:43
@Daniel Exactly. For every line you need to determine its indentation, and print exactly as manytabs
– andersource
Nov 23 '18 at 18:55
add a comment |
Use
print(string + "nt" + string "ntt" + string)
In your code, the third line only contains one tab
indent (indents don't "carry over" to the next lines, so you have to indent every line from the start).
1
Thanks for answer! So if I had to do something like printing a complex indented list I would have to use some kind a variable that would track the number of indentations I'm using?
– Daniel
Nov 23 '18 at 18:43
@Daniel Exactly. For every line you need to determine its indentation, and print exactly as manytabs
– andersource
Nov 23 '18 at 18:55
add a comment |
Use
print(string + "nt" + string "ntt" + string)
In your code, the third line only contains one tab
indent (indents don't "carry over" to the next lines, so you have to indent every line from the start).
Use
print(string + "nt" + string "ntt" + string)
In your code, the third line only contains one tab
indent (indents don't "carry over" to the next lines, so you have to indent every line from the start).
answered Nov 23 '18 at 18:39
andersourceandersource
51418
51418
1
Thanks for answer! So if I had to do something like printing a complex indented list I would have to use some kind a variable that would track the number of indentations I'm using?
– Daniel
Nov 23 '18 at 18:43
@Daniel Exactly. For every line you need to determine its indentation, and print exactly as manytabs
– andersource
Nov 23 '18 at 18:55
add a comment |
1
Thanks for answer! So if I had to do something like printing a complex indented list I would have to use some kind a variable that would track the number of indentations I'm using?
– Daniel
Nov 23 '18 at 18:43
@Daniel Exactly. For every line you need to determine its indentation, and print exactly as manytabs
– andersource
Nov 23 '18 at 18:55
1
1
Thanks for answer! So if I had to do something like printing a complex indented list I would have to use some kind a variable that would track the number of indentations I'm using?
– Daniel
Nov 23 '18 at 18:43
Thanks for answer! So if I had to do something like printing a complex indented list I would have to use some kind a variable that would track the number of indentations I'm using?
– Daniel
Nov 23 '18 at 18:43
@Daniel Exactly. For every line you need to determine its indentation, and print exactly as many
tabs
– andersource
Nov 23 '18 at 18:55
@Daniel Exactly. For every line you need to determine its indentation, and print exactly as many
tabs
– andersource
Nov 23 '18 at 18:55
add a comment |
Considering you want to do this multiple times it is best to use a loop such as this:
n = 10 // amount of times you want to print
for x in range(n):
tabs = "t"*x
print(tabs+"String"+"n")
add a comment |
Considering you want to do this multiple times it is best to use a loop such as this:
n = 10 // amount of times you want to print
for x in range(n):
tabs = "t"*x
print(tabs+"String"+"n")
add a comment |
Considering you want to do this multiple times it is best to use a loop such as this:
n = 10 // amount of times you want to print
for x in range(n):
tabs = "t"*x
print(tabs+"String"+"n")
Considering you want to do this multiple times it is best to use a loop such as this:
n = 10 // amount of times you want to print
for x in range(n):
tabs = "t"*x
print(tabs+"String"+"n")
answered Nov 23 '18 at 18:44
Tobias WilfertTobias Wilfert
7472920
7472920
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53451566%2ftrying-to-do-multiple-tabs-using-t%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
I'm not sure why you expect your first result. You start a new line, and then have a single tab. If you want two tabs, you need to put two tabs.
– Daniel Roseman
Nov 23 '18 at 18:39
n jumps to a new line, but does o to the beginning of the line
– Tobias Wilfert
Nov 23 '18 at 18:39