Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to display what I write on sublime text editor on the CMD
#1
Hi everyone!

Im totally, Totally, Totally new with coding, and that my first ever post on a coding forum.

Im learning Python, for almost two weeks now, so be gentle with me when you're gonna explain Big Grin

So Im using Sublime Text editor to write my Python codes and then displaying them using CMD on my Windows 10.

I try to display this code but when I run it on CMD...I get nothing.

Here is my code:

mystring="abcdefjhigklmnopqrst"

mystring[4:]
mystring[4:2]
mystring[4:2:3]
Do I need to add some built-in keywords to display the result on the CMD window?? Cry
buran wrote Feb-04-2019, 01:36 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Quote
#2
You need to use print() for this

mystring="abcdefjhigklmnopqrst"
 
print(mystring[4:])
print(mystring[4:2])
print(mystring[4:2:3])
Note that second and third one will display nothing because end index of slicing (i.e. 2) is less than start index of slicing (i.e. 4)
Quote
#3
Hi @Buran!

Thanks a lot.

still I didnt understand what you want to say by "Note that second and third one will display nothing because end index of slicing (i.e. 2) is less than start index of slicing (i.e. 4)"

Would you please explain it further?
buran wrote Feb-04-2019, 01:59 PM:
Please, don't edit post after reply has been posted
Quote
#4
Did you run the code provided?
The output is

Output:
efjhigklmnopqrst >>>
as you can see it prints just one line with text and 2 empty lines.
What you do is called slicing.. It can be applied to any sequence, in this case - a string
so the format is [start:end:step]. Note that end and step are optional.

in your case you have:
[4:] - that is start from index 4, till the end and step=1 (remember end and step are optional). that is what gives you efjhigklmnopqrst
[4:2] - that is start=4, end=2, step=1, effectively you ask python to start from index 4 and up to, but not including index=2. Because 2<4 you get empty line
[4:2:3] - same as the above, but step=3, i.e. you ask for every third char, starting from index 4, but up to and not including index 2. Again you get empty line.
Quote
#5
Many Thanks Buran!

Thanks a lot.

You will always be the first one who evr helped me with coding in general. :)
Quote
#6
(Feb-04-2019, 01:58 PM)el_bueno Wrote: You will always be the first one who evr helped me with coding in general. :)
Enjoy the journey. There will always be new and exciting things to learn. :-)
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  read text file and write into html with correct link jacklee26 4 322 Aug-02-2019, 05:48 AM
Last Post: jacklee26
  Running python from Sublime Text editor balley810 2 360 Jul-14-2019, 03:40 PM
Last Post: ThomasL
  error running python in sublime text3 srm 3 366 Jun-22-2019, 09:59 AM
Last Post: srm
  write image into string format into text file venkat18 2 475 Jun-01-2019, 06:46 AM
Last Post: venkat18
  Super with Sublime Text - TypeError: super() takes at least 1 argument (0 given) Shafla 6 937 May-04-2019, 08:30 PM
Last Post: Shafla
  write each line of a text file into separate text files and save with different names Shameendra 3 440 Feb-20-2019, 09:07 AM
Last Post: buran
  run from Python3 text editor ryanb 2 510 Nov-04-2018, 02:58 AM
Last Post: ryanb
  How to display <IPython.core.display.HTML object>? pythopen 2 13,057 Oct-17-2018, 06:22 PM
Last Post: pythopen
  Can't run my code in sublime craver35 2 578 Sep-08-2018, 11:34 AM
Last Post: craver35
  Connecting Anaconda with Sublime Text 3 Atsuko_Zeppeli 2 1,032 Jul-29-2018, 05:21 PM
Last Post: Atsuko_Zeppeli

Forum Jump:


Users browsing this thread: 1 Guest(s)