Jump to content

'str' object has no attribute 'append'

Hafiz75
filename4= input("Enter The File Name? \n")
            confile1="LogoArt.txt"
            f = open(confile1, 'r')
            confile1.append("hi")
            a = 0
            for i in range(len(confile1)):
                try:
                    if (confile1[i] in confile1) >0:
                        a = a + 1
                    if confile1[i] != confile1[i+1]:
                        print(confile1[i],a)
                        a = 0
                except IndexError:
                    print()
        

I dont understand the syntax please could someone help?

CPU: Ryzen 5 2600X | Motherboard: MSI B450M Mortar (Black) RAM: Corsair Vengeance LPX 16GB (2x 8GB) 3000MHz DDR4 | GPU: MSI Radeon RX 580 ARMOR 8GB | Storage: Samsung 860 QVO 1TB and Samsung 970 EVO 250GB | PSU: Corsair CX650M 650W Case: Cooler Master MasterBox Q300L | Monitor: ASUS VZ279HE | Mouse: Logitech M171 Wireless | Keyboard: Cherry DC 2000 | Mousepad: None | Speakers: Logitech Z333

Link to comment
Share on other sites

Link to post
Share on other sites

if i'm not wrong .append only works with lists

lst = [1, 2, 3]
lst.append(4)
print(lst)

this should give you [1, 2, 3, 4]

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, _d0nut said:

if i'm not wrong .append only works with lists


lst = [1, 2, 3]
lst.append(4)
print(lst)

 this should give you [1, 2, 3, 4]

ok thanks xxx

CPU: Ryzen 5 2600X | Motherboard: MSI B450M Mortar (Black) RAM: Corsair Vengeance LPX 16GB (2x 8GB) 3000MHz DDR4 | GPU: MSI Radeon RX 580 ARMOR 8GB | Storage: Samsung 860 QVO 1TB and Samsung 970 EVO 250GB | PSU: Corsair CX650M 650W Case: Cooler Master MasterBox Q300L | Monitor: ASUS VZ279HE | Mouse: Logitech M171 Wireless | Keyboard: Cherry DC 2000 | Mousepad: None | Speakers: Logitech Z333

Link to comment
Share on other sites

Link to post
Share on other sites

W

On 6/29/2019 at 5:30 AM, geo3 said:

use the + operator to concatenate strings in Python. 


name = "Mike " + "Smith" 

 

Where did you get that from????

CPU: Ryzen 5 2600X | Motherboard: MSI B450M Mortar (Black) RAM: Corsair Vengeance LPX 16GB (2x 8GB) 3000MHz DDR4 | GPU: MSI Radeon RX 580 ARMOR 8GB | Storage: Samsung 860 QVO 1TB and Samsung 970 EVO 250GB | PSU: Corsair CX650M 650W Case: Cooler Master MasterBox Q300L | Monitor: ASUS VZ279HE | Mouse: Logitech M171 Wireless | Keyboard: Cherry DC 2000 | Mousepad: None | Speakers: Logitech Z333

Link to comment
Share on other sites

Link to post
Share on other sites

23 hours ago, Franck said:

here's the reference. Most language use either + or & to concatenate. Python is in the + team

https://www.pythonforbeginners.com/concatenation/string-concatenation-and-formatting-in-python

Or if you're VB.NET you can use either one because that's not confusing as hell lol

 

to OP: Strings in most languages are immutable; that is to say, you can't change the original string unless you overwrite it with a new string (or if the language allows it, modify the character data itself, either directly or through methods). In the case of appending or concatenating like you're doing, you're actually making a whole new string from the contents of the other strings you specify.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×