1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
ehidna [41]
1 year ago
12

Assume the variable myWord references a string. Write a statement that uses a slicing

Computers and Technology
1 answer:
givi [52]1 year ago
3 0

Answer:

"myWord[-5:]"

Explanation:

So whenever you slice a string, the syntax in python is expressed as:

string[a:b:c]

where a=start index (this is included in the sliced string)

b = end index (this is excluded from the sliced string)

c = increment

If any of these are included, they are set to default values, where a=0, b=len(string), and c=1.

The increment isn't necessary here, and it's just so you know the syntax a bit more

Anyways, I'm assuming when the question asks to display "the last 5 characters in the string" it means in order? e.g "abcdefghijk" -> "ghijk" and not "abcdefghijk" -> "kjihg"

The last piece of information to know is what a negative index represents.

For example if I have the piece of code

"

string = "hello world"

print(string[-1])

"

This will output "d", and the negative 1 represents the last letter. If you did -2, it would output the 2nd to last letter and so on.

So to print the last 5 characters, we simply use the -5 as the starting index.  

"

string = "hello world"

print(string[-5:])

"

This will print "world" or in other words, the last 5 letters. The reason for this is because the -5 in the first spot means the starting index is the 5th to last letter, and when you have the : after the -5, this is the way of telling python you're slicing the string, and not indexing 1 character. You don't need to include another value after that, because it will default to the last index of the string, or more specifically the last index + 1, since the last index is still included.

So the last thing to know, is that if the string isn't greater than 5 characters, it just prints the entire string, and no errors are raised. You can test this out your self as well. So whenever you have a string that's less than 5 characters the entire string is outputted.

You might be interested in
Please help me on this I don't know which one they are​
Nutka1998 [239]
Hi, the photo doesn’t show the question on what to answer, all I see are empt boxes, if you message me the question I will answer it for you!
7 0
3 years ago
Read 2 more answers
What would be the best thing you could do to prepare yourself to work for a company that has embraced globalization. A) learn ho
laila [671]

Answer:B

Explanation: your co workers might not know English so you would need to learn their language :)

5 0
3 years ago
Read 2 more answers
Photo editing software, desktop publishing, email and word processing software is most likely to be used by:
FrozenT [24]

Answer:

c) mass media personnel

Explanation:

A software can be defined as a set of executable instructions (codes) or collection of data that is used typically to instruct a computer how to perform a specific task and to solve a particular problem.

Basically, softwares are categorized into two (2) main categories and these are;

I. System softwares.

II. Utility softwares.

Photo editing software, desktop publishing, email and word processing software is most likely to be used by a mass media personnel because he or she deals with the creation of various documents such as images, texts, multimedia files etc.

4 0
2 years ago
What happens to a mechanical system when two opposing torques do not cancel out?
const2013 [10]
The system will move in the direction of the stronger torque
5 0
3 years ago
WHO WANTS TO PLAY AMONG US
Elza [17]

Answer:

Explanation:

ME

8 0
3 years ago
Read 2 more answers
Other questions:
  • You are attempting to update a Windows image that has been mounted under C:\mount on your local system. What command must you us
    13·1 answer
  • You are troubleshooting an interface issue on your cisco ios isr. the output of "show ip interface brief" indicates that etherne
    11·1 answer
  • Learning about public speaking can help improve your ________________.
    15·1 answer
  • Think about the five steps to writing an algorithm. Why is each step necessary? Why is it important to be precise when writing c
    15·1 answer
  • Write a class named RetailItem that holds data about an item in a retail store. The class should store the following data in att
    15·1 answer
  • When you perform an in-place upgrade to windows 8.1 from windows 7, what will be names of the “windows” folders in windows 7 and
    5·1 answer
  • What is online school like 6 sentences
    12·1 answer
  • Consider a disk that rotates at 3600 rpm. The seek time to move the head between adjacent tracks is 2 ms. There are 32 sectors p
    5·1 answer
  • Modify the program you wrote for Chapter 6 Exercise 6 so it handles the following
    15·1 answer
  • Capstone Project part 11 quiz
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!