Trying to do multiple tabs using t












0















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?










share|improve this question




















  • 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
















0















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?










share|improve this question




















  • 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














0












0








0








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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














  • 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












3 Answers
3






active

oldest

votes


















0














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")





share|improve this answer































    0














    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).






    share|improve this answer



















    • 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 many tabs

      – andersource
      Nov 23 '18 at 18:55



















    0














    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")





    share|improve this answer























      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
      });


      }
      });














      draft saved

      draft discarded


















      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









      0














      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")





      share|improve this answer




























        0














        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")





        share|improve this answer


























          0












          0








          0







          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")





          share|improve this answer













          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")






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 18:44









          Vasilis G.Vasilis G.

          3,5332722




          3,5332722

























              0














              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).






              share|improve this answer



















              • 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 many tabs

                – andersource
                Nov 23 '18 at 18:55
















              0














              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).






              share|improve this answer



















              • 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 many tabs

                – andersource
                Nov 23 '18 at 18:55














              0












              0








              0







              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).






              share|improve this answer













              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).







              share|improve this answer












              share|improve this answer



              share|improve this answer










              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 many tabs

                – andersource
                Nov 23 '18 at 18:55














              • 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 many tabs

                – 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











              0














              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")





              share|improve this answer




























                0














                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")





                share|improve this answer


























                  0












                  0








                  0







                  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")





                  share|improve this answer













                  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")






                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 23 '18 at 18:44









                  Tobias WilfertTobias Wilfert

                  7472920




                  7472920






























                      draft saved

                      draft discarded




















































                      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.




                      draft saved


                      draft discarded














                      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





















































                      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







                      Popular posts from this blog

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      TypeError: fit_transform() missing 1 required positional argument: 'X'