I'm just wondering how I would fix this

app = first[0:8] and second[0:8]

That doesn't work but if I remove "and..." it does but I need both.

Edited 7 Years Ago by DEATHMASTER: n/a

I'm just wondering how I would fix this

app = first[0:8] and second[0:8]

That doesn't work but if I remove "and..." it does but I need both.

can you do
f = first[0:8]
s = second[0:8]
apps = f+s or whatever comination you require it for

I get the same thing with that (nothing).

Just to clear things up does second refer to the same text as first?

Just to clear things up does second refer to the same text as first?

No it's a different string of text.

What are you trying to do?

>>> first = 'stringisfun'
>>> second = 'iamsecond'
>>> app = first[0:8]
>>> app
'stringis'
>>> app1 = second[0:8]
>>> app1
'iamsecon'
>>> app + app1
'stringisiamsecon'
>>>

"and or" are used for decision control(Boolean logic)
So if you want both first and second to run that will never work.

#both test conditions are true and it print
>>> a = 4
>>> if a > 3 and a < 10:
	print 'this work'
	
this work

#if one is false it will not print
>>> if a > 3 and a > 10:
	print 'this work'


#if we use "or" only one test conditions has to be true.
>>> if a > 3 or a > 10:
	print 'this work'

this work

I see how that works, a little more specifically I'm trying to use it in this which isn't working

if input.find(app + app1) == 1:
    print "output"

input is a method that is build in to python.
And you can not do this input.find

>>> input.find

Traceback (most recent call last):
  File "<pyshell#53>", line 1, in <module>
    input.find
AttributeError: 'builtin_function_or_method' object has no attribute 'find'

>>> input('your number: ')
your number: 5
5

And comparing app,app1 to 1 is always false.

>>> app == 1
False
>>>

Edited 7 Years Ago by snippsat: n/a

input was defined earlier in the code and another example of a how the "== 1" works in this same part of the 'if' statement:

elif input.find(diffstring) == 1:
            print "Ousted."

That part works, but simply making it input.find(diffstring + app) == 1
makes it not work, but I need to refer to those 2 strings without changing them.

input was defined earlier in the code

Dont ever do that.

>>> input = 'hi'
>>> input
'hi'
>>> dir(input)
['__add__', '__class__', '__contains__', '__delattr__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__getslice__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '_formatter_field_name_split', '_formatter_parser', 'capitalize', 'center', 'count', 'decode', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'index', 'isalnum', 'isalpha', 'isdigit', 'islower', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
>>>

Now input works as a string method.
And you can use input.find(),but this is very wrong.
Dont ever use build in python method as variables.

If you not sure use "my" before so my_input.

app = 'abc'
app1 = 'def'
my_input= 'xabcdefgh'

# find() returns the index at which app+app1 ('abcdef')
# appears in string my_input, this should print output
if my_input.find(app + app1) == 1:
    print "output"

Do not under any circumstances use 'input' as a variable name for your string! If you got the code from someone else, it is crap!

If you use 'input' as a variable name early on in your code, you cannot use the function input() later, because 'input' is now a key in the global dictionary and identifies a string object not a function.

Ok I did precisely that (but app = array) ^ with input renamed to my_input and it still doesn't give the print statement.

Also what's all these -1 on my posts in this thread?

Edited 7 Years Ago by DEATHMASTER: n/a

At this point you need to give us the whole code, otherwise we will talk about some nebulous thing for ever.

I am not sure what -1 you are talking about.

Note:
Okay, now I see all those -1 in front of every newer thread (not post).
I looked into it and found out that it is associated with the up and down arrows that are a new feature here, and are supposed to be some kind of a flaky rating system.

It looks like some clown from the C forum who hates Python went around and down clicked all the authors of newer threads! The new feature is rather childish to say the least, so I apologize. I have requested for it to be removed.

Edited 7 Years Ago by vegaseat: stupid rating system

This question has already been answered. Start a new discussion instead.