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
  Sublime Text + Anaconda not indenting Python code correctly Maxximiliann 0 124 Jun-13-2020, 06:09 PM
Last Post: Maxximiliann
  switching from pycharm to sublime issue Drifter 2 149 Jun-09-2020, 09:19 PM
Last Post: Drifter
  Contextual pop-up menus in Sublime Text Mondata 4 233 Apr-08-2020, 06:32 PM
Last Post: buran
  Sublime Text 3 WinError 2 File Specified HelloWorld17 0 192 Apr-02-2020, 09:03 AM
Last Post: HelloWorld17
  Sublime text not responding Mat 1 175 Mar-23-2020, 11:42 AM
Last Post: Fre3k
  Write text expander in Python constantin01 5 446 Jan-16-2020, 08:28 AM
Last Post: buran
  Sublime text 3 and lxml DreamingInsanity 2 616 Dec-22-2019, 01:49 PM
Last Post: DreamingInsanity
  read text file and write into html with correct link jacklee26 4 584 Aug-02-2019, 05:48 AM
Last Post: jacklee26
  Running python from Sublime Text editor balley810 2 706 Jul-14-2019, 03:40 PM
Last Post: ThomasL
  error running python in sublime text3 srm 3 998 Jun-22-2019, 09:59 AM
Last Post: srm

Forum Jump:


Users browsing this thread: 1 Guest(s)