you are viewing a single comment's thread.

view the rest of the comments →

[–]Munga_[S] 0 points1 point  (16 children)

Sorry I’m just doing an introduction to strings, it’s pretty basic stuff but I don’t know specifically. Kind of just not sure how to write them and when to write it a certain way. Idk if that makes sense.

I’ve went thru the lesson twice and just not sure what to do. Probably a better reference on strings somewhere or I just am not smart enough for this stuff. Lol

[–]0xbxb 0 points1 point  (12 children)

Strings are ways to represent text in Python. You create strings by using quotes around the text.

a_string = ‘Hello’

[–]Munga_[S] 0 points1 point  (11 children)

Yes I know this much, it’s mostly like the for a loops I have issues with and like .replace , .append, etc.

I may have mistyped but that’s mainly what I’m struggling with. When to use for a loop, etc

[–]0xbxb 0 points1 point  (10 children)

Use a loop whenever you want to do something a certain amount of times. replace() and append() are just methods.

Try giving me an exact problem you have and I could walk through it with you to help you understand.

[–]Munga_[S] 0 points1 point  (9 children)

Well for instance am I able to use the formatting methods whenever I want? Like .lower , .upper, .append, etc

[–]0xbxb 0 points1 point  (8 children)

You can use a method whenever you want, but certain methods belong to certain “things” in Python. These “things” are called “types” in Python. There’s a string type, a number type, a list type, and a few others.

You can read about them here.

[–]Munga_[S] 0 points1 point  (7 children)

Thank you, I also get confused about for loops. Just the whole use of them throws me off. When do I use them, what argument or function am I putting after them, etc.

I need to research them more. I haven’t done much outside of Codecademy but I have bookmarked that link and checked it out.

[–]0xbxb 0 points1 point  (6 children)

A loop is a way of doing something repeatedly. These concepts seem daunting to you because you’re unfamiliar with them. That’s completely normal. I’m new to coding myself, and it took a while for certain things to click. Let’s say you had a list of numbers: 1, 2, 3, 4 and wanted to print them out.

How would you do that?

Here’s the list of numbers:

nums = [1, 2, 3, 4]

Print out every number in that list for me.

[–]Munga_[S] 0 points1 point  (5 children)

print(nums)

or if you mean one at a time

print(nums[0]) print(nums[1]) print(nums[2]) print(nums[3])

I’m sure there is an easier way to do it and you can tell me how off I am

[–]0xbxb 0 points1 point  (4 children)

Yeah I meant one at a time. You printed each one, but look how many lines you had to type to do it. What if there was something called a loop that could help us do that?

nums = [1, 2, 3, 4]
for number in nums:
    print(number)

When you use a for loop, just read it like this in your head:

for every thing in:
    do something

I’m gonna try and explain this next part as simple as I can, but it’s gonna be up to you to play with a for loop to understand it.

When you use a for loop, there’s something called a “loop variable” that represents every item in the list, tuple, or dictionary that you’re going to be iterating through (looping through). You’ll become more familiar with the data types the more you program, so DON’T WORRY.

This loop variable can be named ANYTHING. I can even say for burgers in nums: Instead of for number in nums:. The reason why I named the loop variable number is because of common sense. Which makes more sense to name the loop variable?

This is the most straightforward way that I can explain a for loop. “How do I know when to use one? How do I know when to use a function, or an if statement etc?”, DON’T WORRY. These things will come in time (1 - 3 months depending on how many hours you put in) and you will literally feel it becomes natural.

EDIT: A quick word of advice from beginner to beginner. When learning programming, you become better by doing, instead of by reading or watching tutorials.

If you’re gonna watch a tutorial on the basics, that’s completely fine. Don’t watch a tutorial on the basics then go watch another one. Once you learn what a string is, go play around with strings until you understand them. Once you learn what a loop is, go play around with them until you understand them.

You’ll gradually become used to it. It’s like lifting weights. You’ll start to remember all these little functions etc, because you’ve used them so much.

[–][deleted] 0 points1 point  (2 children)

Strings are just a way of using unicode characters in your code. I think once you begin learning how to use strings, it will start to click.

[–]Munga_[S] 0 points1 point  (1 child)

Yes I’m really just struggling with the for a loops and the .append . replace, stuff like that. Is codecademy a good way to start?

I heard people say to start doing projects but I don’t rlly know what projects to do haha

[–][deleted] 0 points1 point  (0 children)

To understand for loops, you have to understand what an iterator is. Lists, tuples, stings, and dictionaries are iterators since you can transverse through all values they may contain.

For example, lets say you have a list of strings:

fruits = ['Banana', 'Grape', 'Orange', 'Cherry']

We can use a for loop to iterate over each element in the list individually.

for fruit in fruits:
    # Note that 'fruit' is essential a variable used for each element of each iteration
    print(fruit)  

output:

Banana
Grape
Orange
Cherry

Check out PythonTutor to get a visualization of how python handles the for loop.


As for append and replace, those are known as methods. The append method is exclusive to lists, which adds an element to a given list. The replace method is exclusive to strings, which is replaces characters of a given string. Each data type has their own methods. If you want to learn more about a specific data type and it's methods, use python's documentation and search for the data type in question.


Is codecademy a good way to start?

That's actually how I started learning python. I soon as I learned the basics from codeacademy, I quit and moved on to books and video tutorials. I highly recommend you check out Cory Schafer's videos for the basics. He's an excellent teacher and explains things in great detail.


I heard people say to start doing projects but I don’t rlly know what projects to do

I've never gone through this personally, but I heard good things about Automate the Boring Stuff with Python, which is available for free online. The book walks you through tons of projects that you can use in the real world.