Tag: Syntax
Posts of Tag: Syntax
  1. Difference between Syntax and Semantics

    Difference between Syntax and Semantics Here you will learn about difference between Syntax and Semantics with example. The both terms might seem the same things but they are not, they are just interrelated con...Learn More
    ProgrammingSyntaxSemantics
  2. How can I closely achieve ?: from C++/C# in Python?

    In C# I could easily write the following: string stringValue = string.IsNullOrEmpty( otherString ) ? defaultString : otherString; Is there a quick way of doing the same thing in Python or am I stuck with an 'i...Learn More
    PythonSyntaxternary-operatorsyntax-rules
  3. Mixed syntax for control structures generating syntax errors

    I'm refactoring some PHP code and discovered that certain nested combinations of if () : and if () { generate syntax errors. Not that I would normally mix the two, but I like to do frequent syntax checks a...Learn More
    PHPSyntax
  4. Using for...else in Python generators

    I'm a big fan of Python's for...else syntax - it's surprising how often it's applicable, and how effectively it can simplify code. However, I've not figured out a nice way to use it in a generator, for example:...Learn More
    PythonSyntaxGeneratorYieldfor-loop
  5. In Python, how I do use subprocess instead of os.system?

    I have a Python script that calls an executable program with various arguments (in this example, it is 'sqlpubwiz.exe' which is the "Microsoft SQL Server Database Publishing Wizard"): import os sqlpubwiz = r'"...Learn More
    PythonSyntaxProcessScripting
  6. Which is more preferable to use in Python: lambda functions or nested functions ('def')?

    I mostly use lambda functions but sometimes use nested functions that seem to provide the same behavior. Here are some trivial examples where they functionally do the same thing if either were found within ano...Learn More
    PythonFunctionSyntaxlambda
  7. How can I concatenate regex literals in JavaScript?

    Is it possible to do something like this? var pattern = /some regex segment/ + /* comment here */ /another segment/; Or do I have to use new RegExp() syntax and concatenate a string? I'd prefer to use the ...Learn More
    JavaScriptSyntaxregex
  8. What does ** (double star) and * (star) do for Python parameters?

    In the following method definitions, what does the * and ** do for param2? def foo(param1, *param2): def bar(param1, **param2): ...Learn More
    PythonSyntaxKwargsparameter-passingidentifier
  9. Can you add new statements to Python's syntax?

    Can you add new statements (like print, raise, with) to Python's syntax? Say, to allow.. mystatement "Something" Or, new_if True: print "example" Not so much if you should, but rather if it's possible (sh...Learn More
    PythonSyntax
  10. What does += mean in Python?

    I see code like this for example in Python: if cnt > 0 and len(aStr) > 1: while cnt > 0: aStr = aStr[1:]+aStr[0] cnt += 1 What does th...Learn More
    PythonSyntax
  11. How can I do a line break (line continuation) in Python?

    I have a long line of code that I want to break up among multiple lines. What do I use and what is the syntax? For example, adding a bunch of strings, e = 'a' + 'b' + 'c' + 'd' and have it like this: e = 'a' +...Learn More
    PythonSyntaxline-breakslong-lines
  12. Why does Java not have block-scoped variable declarations?

    The following method does not work because the inner block declares a variable of the same name as one in the outer block. Apparently variables belong to the method or class in which they are declared, not to t...Learn More
    JavaSyntaxlanguage-design