Python Forum

Full Version: How to display what I write on sublime text editor on the CMD
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
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)
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?
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.
Many Thanks Buran!

Thanks a lot.

You will always be the first one who evr helped me with coding in general. :)
(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. :-)