Python Forum
How to display what I write on sublime text editor on the CMD
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
Reply
#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)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#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?
Reply
#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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Many Thanks Buran!

Thanks a lot.

You will always be the first one who evr helped me with coding in general. :)
Reply
#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. :-)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to display <IPython.core.display.HTML object>? pythopen 3 45,708 May-06-2023, 08:14 AM
Last Post: pramod08728
  Read text file, modify it then write back Pavel_47 5 1,501 Feb-18-2023, 02:49 PM
Last Post: deanhystad
  while loop not working-I am using sublime text editor mma_python 4 1,060 Feb-05-2023, 06:26 PM
Last Post: deanhystad
  How to write in text file - indented block Joni_Engr 4 6,363 Jul-18-2022, 09:09 AM
Last Post: Hathemand
  Sublime Text Editor not recognizing Python elroberto 5 2,802 Jun-13-2022, 04:00 PM
Last Post: rob101
  Write to a LCD display using i2c to a Raspberry Pi using i2c 6398 4x20 LCD Aggie64 4 1,533 Apr-28-2022, 07:26 PM
Last Post: Aggie64
  CSV to Text File and write a line in newline atomxkai 4 2,612 Feb-15-2022, 08:06 PM
Last Post: atomxkai
  Music Notation editor; how to build the editor? direction to go? philipbergwerf 1 1,650 Jan-01-2022, 04:56 PM
Last Post: Larz60+
  Code folding in Sublime Text Mondata 2 2,758 Mar-12-2021, 04:16 PM
Last Post: Mondata
  How to link Sublime Text 3 Build system to Python 3.9 Using Windows 10 Fanman001 2 4,532 Mar-04-2021, 03:09 PM
Last Post: martpogs

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020