Posts

Showing posts with the label Operators

Behaviour Of Increment And Decrement Operators In Python

Answer : ++ is not an operator. It is two + operators. The + operator is the identity operator, which does nothing. (Clarification: the + and - unary operators only work on numbers, but I presume that you wouldn't expect a hypothetical ++ operator to work on strings.) ++count Parses as +(+count) Which translates to count You have to use the slightly longer += operator to do what you want to do: count += 1 I suspect the ++ and -- operators were left out for consistency and simplicity. I don't know the exact argument Guido van Rossum gave for the decision, but I can imagine a few arguments: Simpler parsing. Technically, parsing ++count is ambiguous, as it could be + , + , count (two unary + operators) just as easily as it could be ++ , count (one unary ++ operator). It's not a significant syntactic ambiguity, but it does exist. Simpler language. ++ is nothing more than a synonym for += 1 . It was a shorthand invented because C compilers ...

Batch Not-equal (inequality) Operator

Answer : Try if NOT "asdf" == "fdas" echo asdf Use NEQ instead. if "asdf" NEQ "fdas" echo asdf I know this is quite out of date, but this might still be useful for those coming late to the party. (EDIT: updated since this still gets traffic and @Goozak has pointed out in the comments that my original analysis of the sample was incorrect as well.) I pulled this from the example code in your link: IF !%1==! GOTO VIEWDATA REM IF NO COMMAND-LINE ARG... FIND "%1" C:\BOZO\BOOKLIST.TXT GOTO EXIT0 REM PRINT LINE WITH STRING MATCH, THEN EXIT. :VIEWDATA TYPE C:\BOZO\BOOKLIST.TXT | MORE REM SHOW ENTIRE FILE, 1 PAGE AT A TIME. :EXIT0 !%1==! is simply an idiomatic use of == intended to verify that the thing on the left, that contains your variable, is different from the thing on the right, that does not. The ! in this case is just a character placeholder. It could be anything. If %1 has content, then the equality will be fals...