0

I tried to do something like this:

string='bla'+if string[len(string1)='x':
                       True:
                       deletter='blabla'

this is the code:

tperfectcompus='am '+verb+if verb[len(verb)-2]='c':
                                True
                                theletter='esc'
quamrana
  • 37,849
  • 12
  • 53
  • 71
  • 1
    `'bla' + ('something' if condition else 'something else')` – Barmar Jan 24 '23 at 20:48
  • There is a way to do this in Python (the "ternary" statement as in @Barmar 's comment), but this is trying to be too clever by far. Why not just use `string = 'blah'; if (whatever): string += 'blabla'` – Max Jan 24 '23 at 20:48
  • How is concatenating a string with `True` supposed to work out? – John Coleman Jan 24 '23 at 20:48
  • Also you should be using `==` for comparison, not `=` – Barmar Jan 24 '23 at 20:49
  • @JohnColeman I'm guessing this is some analogy to a C switch statement, rather than trying to append True. – Max Jan 24 '23 at 20:49
  • A little more pythonic way of `verb[len(verb) - 2]` is by replacing it with `verb[-2]` – jvx8ss Jan 24 '23 at 21:00

0 Answers0